开发者

Completely finish the actitvity

In made the android app. I installed it in my mobile. When I press back button on my mobile it comes out of the app. But it is running in the background. So, how can I finish the activity com开发者_如何学Cpletely? I wrote the code onkeydown event also. Even it is running in background.


You should override the onStop() method on your activity and in call the finish() method from it. Don't forget to call super.onStop() at the beginning of the onStop() method. As far as I know it's not running on the background, android saves the state of the activity and when it comes back, it restores your activity with the same state it was.


You can call Activity.finish() to kill of an activity completely.

Be aware that this it not something your should normally do, as Android really want to manage the activity life cycle for you, as mentioned by Sheikh Aman.


Hi see the following link in that also same question is available.Finish the android application completely


I will keep running in the background. Android decides when to kill your activity.

By the way, How do you ensure that it is running and "working" (is not frozen) ??


In your onKeyDown() handler you should add this:

finish();

This causes the activity to be closed.


Call this:

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

It's odd, but only this call guarantees that you will kill your application. Due to specific Android life-cycling neither finish() nor any other methods doesn't kill application.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜