Related information:
Http://www.delphitop.com/html/Android/2933.html
Precautions:
Using Movetasktoback/movetasktofront requires the application to have reorder tasks authorization, and if there is no permission, the program will be rolled back when executed.
Instance code:
1 UnitUnit1;2 3 Interface4 5 uses6 system.sysutils, System.types, System.uitypes, system.classes, System.variants,7 FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs,8 FMX. Controls.presentation, Fmx.stdctrls, FMX. Scrollbox, FMX. Memo;9 Ten type OneTForm1 =class(Tform) A Timer1:ttimer; - Button1:tbutton; - Label1:tlabel; the Button2:tbutton; - Button3:tbutton; - Memo1:tmemo; - procedureButton1Click (sender:tobject); + procedureButton2click (sender:tobject); - procedureButton3click (sender:tobject); + procedureTimer1timer (sender:tobject); A Private at {Private Declarations} - Public - {Public Declarations} - End; - - var in Form1:tform1; - to Implementation + uses -ANDROIDAPI.JNI.APP,//need to introduce theAndroidapi.JNI.GraphicsContentViewText,//need to introduce *Androidapi.helpers,//need to introduce $Androidapi.JNI.JavaTypes,//need to introducePanax NotoginsengAndroidapi.jnibridge;//need to introduce - the //using Movetasktoback/movetasktofront requires the application to have reorder tasks authorization, and if there is no permission, the program will be rolled back when executed. + A {$R *.FMX} the //method One: Hide the program + procedureNo1sendapptoback; - var $ intent:jintent; $ begin -Intent:= tjintent.Create; - intent.setaction (TJIntent.JavaClass.ACTION_MAIN); the intent.setflags (TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); - intent.addcategory (TJIntent.JavaClass.CATEGORY_HOME);Wuyi sharedactivitycontext.startactivity (intent); the End; - Wu //method Two: Get the activity manager - functionSharedactivitymanager:jactivitymanager; About var $ Aservice:jobject; - begin -Aservice: =Sharedactivitycontext.getsystemservice (TJContext.JavaClass.ACTIVITY_SERVICE); -Result: = Tjactivitymanager.wrap ((aservice asilocalobject). Getobjectid); A End; + the //method Two: Hide the program - procedureNo2sendapptoback; $ begin the //Online said XE7 is supported, but I use XE8 don't know why not. the //Sharedactivitymanager.movetasktoback (sharedactivity.gettaskid,tjintent.javaclass.flag_activity_new_task); the End; the - //method Two: Display the program in procedureNo2sendapptofront; the begin the Sharedactivitymanager.movetasktofront (sharedactivity.gettaskid,tjintent.javaclass.flag_activity_new_task); About End; the the //Hide the program and display it after 5 seconds the procedureTform1.button1click (sender:tobject); + begin - //Hide Programs the No1sendapptoback;Bayi //turn on the timer and show the program (5 seconds later) theTimer1.enabled: =True; the End; - - procedureTform1.button2click (sender:tobject); the begin the //Hide Programs the No2sendapptoback; the End; - the procedureTform1.button3click (sender:tobject); the begin the //Show Programs94 No2sendapptofront; the End; the the procedureTform1.timer1timer (sender:tobject);98 begin About //Show Programs - No2sendapptofront;101Timer1.enabled: =False;102 End;103 104 End.
Android Instance-Program switch to background and switch from background to foreground