开发者

Killing The Application In Android

I have an application which shows a notification in the status bar for users to click to get resumed into the activity.

In the application, I will also have a close application button which runs:

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

When I click the close app button, the app will get killed as long as I didn't enter the app throu开发者_开发技巧gh clicking on the notification.

If I have entered the app by clicking on the application, the application will "blink" for a second and a new copy is shown. I suppose a new copy is shown.

Do anyone happen to know what's causing this?


You don't kill apps in android, it isn't the way things work. The user navigates away and the system cleans up whats left when needed. Why do you need a "close" button when the phone already has a Home and Back button?


Killing your application's process is a terrible thing. Depending on what your app is doing, you could potentially leave some resources not cleaned up properly because of how you've abruptly killed things. There's no reason to do this on android. Android will do a better job of managing resources/battery life without your help.

If you really want to add a close button your best bet is to take users back to their home screen.


You said

@Philipp Reichart i tried replacing android.os.Process.killProcess(android.os.Process.myPid()); with finish() but it didn't work. the application wasn't killed

I had a similar situation with one of my applications, and finish() wasn't working so I used .killProcess briefly until I could work out the bugs. But this should not be a permanent solution.

My problem was threads. Make sure all of your threads are properly disposed of when they are finished (close IO streams, db references, cursors, etc...). Once I did this there was no reason for .killProcess as finish() did the job.

Also the Android system was built in with the "back" button to exit and the "home" button to "minimize" (keeps the app in memory). Applications don't need an "exit" button because its already there, which gives you more screen real estate :).


have you tried system.exit(0); in the onDestroy() after you call finish() when the user selects the "close" button,..

even though is NOT recommended

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜