I have an android application which main view consists of a tab-bar with three tabs in it.
When developing and running the application on the device through adb I get the following behavior:
- When clicking the phone button "Home screen" and relaunching the application it seems as the application continues where I was before pressing the button (remembers selected tab etc...) (apparently its still running in the background).
However when I export and sign the appl开发者_Python百科ication (using Eclipse) it suddenly always seem to start a new instance of the application when returning from home screen.
Why does it behave so different in those cases? And what do I need to do in my application in order to always have the "running in background" behavior.
If you always want your application to have "running in background behavior", then set android:alwaysRetainTaskState="true" in your main activity manifest. This prevents Android from periodically resetting your application back to the root activity.
android:alwaysRetainTaskState
It sounds as though your application is being destroyed between the point that you go to the home screen and start the app back up again. This can be due to not having enough memory available on the device. If you have a lot of background apps running on your device this may be the reason it is happening.
I would recommend debugging and checking out which path is being hit, that is, whether or not your app is going through just the onResume lifecycle method, or if it is also going through the onCreate lifecycle method.
精彩评论