參考來源:
https://forums.embarcadero.com/thread.jspa?threadID=252411
首先仰泻,引用單元:
uses
System.DateUtils,
Androidapi.JNI.GraphicsContentViewText,
FMX.Platform.Android,
Androidapi.Helpers,
Androidapi.JNI.App
詳細(xì)代碼:
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;
調(diào)用方法:
ReStartApp();