How do I finish an activity in this instance?
We all know that hitting the back button on the device doesn't kill the application, it merely finishes (destroys) the activity running on the foreground.
Well I have come across some code which helps me capture the back button signal so that I cannot exit the application. The only way to exit it in such cases is to press the ho开发者_开发技巧me key.
Now this situation presents me with a unique disadvantage! The inability to kill finish the application on a time of my own choosing allows the application to keep running in the background like nothing has changed.
So in such cases is the task manager my only friend or is there a way for me to otherwise kill this application?
PS: if there is a flaw in my understanding of what happens when the home button is pressed, I would love to be corrected... =)
There is no way to kill an application with the standard buttons neither the back button or the home button. Your application will be paused if it is not a service and is send to the background, and will look like it is eating up memory but if the application has no tasks running the app is perfectly fine and will not use any resources that are needed by other processes.
As a developer just be sure that you don't change the behaviour of the back button and that you unregister all listener in the onPause method of your activities. This will stop your app from consuming battery and processing power if it is in the background. If you need a background process start it as a service and give the user the possibility to disable it.
This life cycle behaviour is different than that you are used to from a normal machine. But if the apps are written more or less correct it should fit much better to the usage of a mobile device. You should read at least the multi threading the android way on the android blog maybe also the When to include an exit button. That will give you a better understanding of the intended usability patterns on android regarding multi touch and exiting applications.
If you want to finish your application every time when a user clicks home and relaunches your application you can specify this property in your Manifest android:finishOnTaskLaunch="true" . However Android does not permit us to kill an application through code and is not recommend.
精彩评论