码迷,mamicode.com
首页 > 移动开发 > 详细

实现代码重启android app.

时间:2019-08-06 15:44:27      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:finish   unix   ref   lint   man   thread   manager   read   target   

var
  Form1: TForm1;

implementation

uses
  System.DateUtils,
  Androidapi.JNI.GraphicsContentViewText,
  FMX.Platform.Android,
  Androidapi.Helpers,
  Androidapi.JNI.App
  ;
{$R *.fmx}

procedure ReStartApp();
var
  LPM : JPackageManager;
  LIntent_Start : JIntent;
  LPendingIntent : JPendingIntent;
  LMS : Int64;
begin
  LPM := TAndroidHelper.Context.getPackageManager();
  LIntent_Start := LPM.getLaunchIntentForPackage(
      TAndroidHelper.Context.getPackageName()
      );
  LIntent_Start.addFlags( TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP );

  LPendingIntent := TJPendingIntent.JavaClass.getActivity(
      TAndroidHelper.Context,
      223344 {RequestCode},
      LIntent_Start,
      TJPendingIntent.JavaClass.FLAG_CANCEL_CURRENT
      );

// System.currentTimeMillis() is "wall clock time in UTC".
//  LMS := DateTimeToUnix( Now, False {InputIsUTC} ) * 1000; //slow
  LMS := LMS + System.DateUtils.MilliSecondOf( Now ); //Fast

  TAndroidHelper.AlarmManager.&set(
      TJAlarmManager.JavaClass.RTC,
      LMS + 500,
      LPendingIntent
      );

  TAndroidHelper.Activity.finish();

end;

https://forums.embarcadero.com/thread.jspa?threadID=252411 

 

实现代码重启android app.

标签:finish   unix   ref   lint   man   thread   manager   read   target   

原文地址:https://www.cnblogs.com/kinglandsoft/p/11309157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!