如何在Delphi开发环境中实现Android应用的编程式自动重启
Delphi开发Android应用自动重启实现需求
我已掌握部分Windows端应用重启的实现逻辑,目前需要在Delphi开发的Android应用中实现同等功能,暂时未找到可行方案。此前我看到@Mihai Limbășan提出的思路如下:
或许可以跳出固有思维:无需纠结互斥量/实例逻辑,只需创建另一个可执行文件,等待主应用关闭后重新启动它即可。额外优势是后续可通过该机制实现主应用二进制文件更新,也更易实现提权运行,无需在同一应用中维护不同完整性级别等。
我不清楚该方案的具体实现逻辑,也不知道从何入手,希望能获得相关实现提示、代码示例或者其他可行的重启方案。
补充说明
结合相关疑问,我补充以下业务流程的代码片段:
用户选择例如「English」语言并点击保存按钮后,会执行如下代码:
Inifile := TIniFile.Create(fPath); try Inifile.WriteString('Instelling','ip',edit5.text); Inifile.WriteString('Instelling','user',edit6.text); Inifile.WriteString('Instelling','pixels',edit3.text); Inifile.WriteInteger('Instelling','language',Combobox2.ItemIndex); fGebruiker := Edit6.Text; fFotoformaat := StrToInt(edit3.Text); finally FDConnection1.Params.Values['server']:=edit5.Text; FDConnection1.Connected := True; inifile.free; End;
上述代码会将数据写入ini文件,其中也包含语言选择下拉框的选中项索引。
目前我需要手动重启应用,才能让新的语言设置生效,应用启动时加载语言的代码如下:
procedure TfmMain.FormShow(Sender: TObject); VAR param : string; inifile : tInifile; begin if (System.SysUtils.fileexists(fPath)) then Begin begin Inifile := TIniFile.Create(fPath); try if not (Inifile.ReadString('Instelling','ip','default')='default') and not (Inifile.ReadString('Instelling','Gebruiker','default')='default')then try edit5.text := Inifile.ReadString('Instelling','ip','default'); edit6.text := Inifile.ReadString('Instelling','user','default'); Edit3.text := Inifile.ReadString('Instelling','pixel','400'); combobox2.ItemIndex := IniFile.ReadInteger('Instelling','language',1); fpixel:= StrToInt(edit3.Text); fuser:=edit6.text; FDConnection1.Params.Values['server']:=edit5.Text; taal := 'NL'; //find language settings if combobox2.ItemIndex=0 then begin language:= 'NL' end; if combobox2.ItemIndex=1 then begin language:= 'ENG'; end; if language='ENG' then begin vertalerENG.vertaler('ENG'); end; end; end; end; end;
其中VertalerENG是语言切换函数,当语言参数为ENG时会将界面所有标题替换为英文。
当前问题是语言设置修改后必须手动重启应用才会生效,希望能实现自动重启完成配置更新。
内容的提问来源于stack exchange,提问作者user17201964
相关产品推荐
相关产品推荐

