首页 > 代码库 > Android实例-退出程序
Android实例-退出程序
Android实例-退出程序
http://www.cnblogs.com/FKdelphi
unit Unit1;interfaceuses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Label1: TLabel; Button4: TButton; Button5: TButton; Button6: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); procedure Button4Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button5Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: 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}procedure TForm1.Button1Click(Sender: TObject);begin Label1.Text := ‘按返回键将会出现一个对话框!‘;end;procedure TForm1.Button2Click(Sender: TObject);begin MainActivity.finish; { 退出程序 }end;procedure TForm1.Button3Click(Sender: TObject);begin {$IFDEF ANDROID} Application.MainForm.DisposeOf; { 退出程序 } halt(0); {$ENDIF}end;procedure TForm1.Button4Click(Sender: TObject);var Intent: JIntent;begin Intent := 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;procedure TForm1.Button5Click(Sender: TObject);begin Application.Terminate;end;procedure TForm1.Button6Click(Sender: TObject);begin Close;end;//此代码报错,不可用,原因不明。procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);begin if Key = vkHardwareBack then//如果按下物理返回键 begin Label1.Text := ‘1‘; if MessageDlg(‘确认退出吗?‘, TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK, TMsgDlgBtn.mbCancel], -1) = mrOK then MainActivity.finish; { 退出程序 } Key := 0;//必须的,不然按否也会退出 Exit; end;end;end.
Android实例-退出程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。