开发者

How to close an Application? [duplicate]

T开发者_StackOverflow中文版his question already has answers here: Closed 10 years ago.

Possible Duplicate:

Quitting an application - is that frowned upon?

How to exit the current application on a click of any button when I am in the middle of my application?

finish() will only finish the current activity not all the activities.


In Android it is not recommended to exit an application. Read this question for more information on this.

You could use

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

to go back to the home screen on the the press of a button in your app. This will not close your application but put it in the background. You should always in every activity release every battery heavy resources like Sensor Listeners etc. the moment you are send to the background.


you can do that on button click. Define any static method like exit() and define

android.os.Process.killProcess(android.os.Process.myPid()); in exit method

in the main or first activity.

Then call this method on button click.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜