Android Instance-Exit program Http://www.cnblogs.com/FKdelphi
UnitUnit1;Interfaceusessystem.sysutils, System.types, System.uitypes, system.classes, System.variants, FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs, FMX. Controls.presentation, Fmx.stdctrls;typeTForm1=class(tform) Button1:tbutton; Button2:tbutton; Button3:tbutton; Label1:tlabel; Button4:tbutton; Button5:tbutton; Button6:tbutton; procedureButton1Click (Sender:tobject); procedureButton2click (Sender:tobject); procedureButton3click (Sender:tobject); procedureFormkeyup (Sender:tobject;varKey:word;varKeychar:char; Shift:tshiftstate); procedureButton4click (Sender:tobject); procedureButton6click (Sender:tobject); procedureButton5click (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End;varForm1:tform1;ImplementationusesFMX. PLATFORM.ANDROID,FMX. Helpers.android,androidapi.jni.net,androidapi.jni.graphicscontentviewtext,androidapi.jni.javatypes, Androidapi.helpers,system. Ioutils;{$R *.FMX}{$R *. NMXHDPIPH.FMX ANDROID}{$R *. LGXHDPIPH.FMX ANDROID}{$R *. MACINTOSH.FMX MACOS}{$R *. XLGXHDPITB.FMX ANDROID}{$R *. LGXHDPITB.FMX ANDROID}{$R *. GGLASS.FMX ANDROID}procedureTform1.button1click (sender:tobject);beginLabel1.Text:='pressing the back key will bring up a dialog box! ';End;procedureTform1.button2click (sender:tobject);beginMainactivity.finish;{Exit Program}End;procedureTform1.button3click (sender:tobject);begin {$IFDEF ANDROID}Application.MainForm.DisposeOf;{Exit Program}Halt (0); {$ENDIF}End;procedureTform1.button4click (sender:tobject);varintent:jintent;beginIntent:=TJIntent.JavaClass.init (TJIntent.JavaClass.ACTION_MAIN); Intent.addcategory (TJIntent.JavaClass.CATEGORY_HOME); Intent.setflags (TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); Sharedactivitycontext.startactivity (Intent);End;procedureTform1.button5click (sender:tobject);beginapplication.terminate;End;procedureTform1.button6click (sender:tobject);beginClose;End;//This code error, not available, the reason is unknown. procedureTform1.formkeyup (Sender:tobject;varKey:word;varKeychar:char; Shift:tshiftstate);begin ifKey = Vkhardwareback Then//If you press the physical return key beginLabel1.Text:='1'; ifMessagedlg ('are you sure you want to quit? ', Tmsgdlgtype.mtconfirmation, [Tmsgdlgbtn.mbok, Tmsgdlgbtn.mbcancel],-1) = Mrok ThenMainactivity.finish;{Exit Program}Key:=0;//Yes, or you'll quit if you press No.Exit; End;End;End.
Android Instance-Exit program