I recently finished up my very first app on Android and had a pretty basic question that I can't seem to find an answer on. Like with most apps, when one is installed on your phone, it will show up in the Settings -> Applications list. The app I created shows up in the Downloaded section along with other downloaded apps like Facebook and the Google Play store. When one of these apps is selected from this list, two buttons show up at the top - "Force stop" and "Uninstall". Some of the apps on this list have "Force Stop" greyed out (which I'm sure means it has been forced to stop) and other apps will let you click this button.

What I'd like to know is if "Force Stop" is not greyed out and is still clickable, does that mean this is taking some battery life out of my Android device (even if it's a very very small amount) by still doing some kind of process or by taking up resources? I added a finish() method to my new app when a user hits the back button to exit the app but the "Force Stop" button is still clickable. I know Android handles its own stuff and kills apps when it needs to but will my new app be taking some battery life before Android completely kills the app? I'd just like to know for learning purposes and to make sure I don't need to continue to add code to my new app. Thank you.

有帮助吗?

解决方案

It means that your app is running in the background, just like a minimized app on a PC. Finish does not actually kill the app, only the activity (an app can contain multiple activities and services)- any other activity/service will still be running. It will only take up battery power if some service or thread is still around processing, but it will continue to take up RAM. This is how Android normally works and is all expected behavior.

其他提示

When "Force Stop" is available for an app it means that the app is still running in the background. The Android OS handles all memory management for you, when the user exits your app, Android will close your app and "hide" a small portion of it in memory to speed up reload times when the user returns to your app.

Calling finish(); is preferred as force closing an app can sometimes be harmful. If android ever needs the memory it will fully close your app and reclaim the small amount of memory that it held.

If you feel it is absolutely necessary to completely kill your app you can call System.exit();, however it is more user friendly to allow Android to take control of your app once you are done with it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top