如何重新启动从内部应用程序的Andr​​oid应用 [英] How to restart android application from within application

查看:119
本文介绍了如何重新启动从内部应用程序的Andr​​oid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求重新启动,当用户更改preference应用。清除栈犯规帮助我,因为这并不取消后端服务电话。我想杀死应用程序本身。我使用

I have a requirement to restart the application when the user changes a preference. Clearing the stack doesnt help me since this doesnt cancel the backend service calls. I want to kill the application process itself. I am using

Process.killProcess(Process.myPid());

和它为我杀的应用程序。但是,我需要的是重新启动应用程序。是指杀死进程,引发新工艺,使该应用程序重新开始一次。

and it works for me to kill the application. But what i need is to restart the application. Means kill the process and trigger a new process so the application start fresh once again.

有没有办法做到这一点?

Is there a way to do this?

在此先感谢。

推荐答案

这是不是其中之一或许应该尝试做一个测试环境之外。

This is not something which one should probably attempt to do outside of a testing environment.

这是说,两个思路:

1)在不久的将来,将有一段时间报警,然后杀了你的流程

1) Set an alarm for some time in the very near future and then kill your process

2)启动其他的东西(也许是小本机进程或shell脚本),将检测到你的死亡,并通过一个意图重新启动您

2) Start up something else (perhaps a small native process or shell script) that will detect your death and restart you via an intent

您也可以尝试发射了一个意图,开始自己,然后迅速凋零,但是这听起来像依赖于实现一个潜在的竞争状态。如果你抓住了粘合剂FD出来的/ proc,并在当地code做了恶事,你也许能断火意图以这样的方式从读写控制返回您的应用程序崩溃...

You could also try firing off an intent to start yourself and then dying quickly, but this sounds like a potential race condition depending on implementation. If you grabbed the binder fd out of /proc and did evil things in native code, you might be able to fire off the intent in such a way that your application crashes on the return from the ioctl...

这篇关于如何重新启动从内部应用程序的Andr​​oid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆