开发者

Restart Android Process While Returning Activity Result?

开发者 https://www.devze.com 2023-03-09 13:01 出处:网络
I want the ability to start my activity in a new process and end the current instance of my activity in its current process.

I want the ability to start my activity in a new process and end the current instance of my activity in its current process.

The second part is easy enough with:

android.os.Process.killProcess(android.os.Process.myPid());

The first part I can not find a documented way to do. I can however get the same effect if I do the following:

((Activity)context).setResult(reason);
((Activity)context).finish();
android.os.Process.killProcess(android.os.Process.myPid());

where the activity was started for a result. This seems to work ev开发者_JAVA技巧ery time. The only side effect is when my activity has no title there is a brief flicker as the new instance removes its title. The activity restarts and the onActivityResult is called with the parameters I had set before killing the last instance of the activity.

Even though this works every time for me now my concern is that this will not work under some circumstances I have not tested or may be considered a bug that is removed from future OS versions.

Is this an expected and correct behaviour?

0

精彩评论

暂无评论...
验证码 换一张
取 消