I'm seeing some interesting activity flow when android turns off the screen and locks the screen... my app goes through the regular flow, onCreate, onStart and onResume. Then, I let my phone sit there. When the screen goes black, onPause is called. That's fine. Then 5 seconds later, the app is killed (onStop, onDestroy). That's fine too. But immediately after onDestroy is called, onCreate, onStart and onResume are called, restarting the app even though the screen is blank. The app has a load time, and it plays a sound when it starts, so it's kind of creepy when the phone you set down 30 seconds ago starts playing sounds. Why does android kill the app then restart it? Target is 2.1-update, and the phone is a Samsung Captivate. Anyone else seeing this, and know a way to stop it?
In your finish() method, you want to use isActivityVisible() to check if the activity is visible or not. There you can also check if the user has selected an option or not. Continue when both conditions are met.
Activity Lifecycle: Activity is one of the building blocks of Android OS. In simple words Activity is a screen that user interact with. Every Activity in android has lifecycle like created, started, resumed, paused, stopped or destroyed. These different states are known as Activity Lifecycle.
An Android activity goes through six major lifecycle stages or callbacks. These are: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.
onPause. Called when the Activity is still partially visible, but the user is probably navigating away from your Activity entirely (in which case onStop will be called next). For example, when the user taps the Home button, the system calls onPause and onStop in quick succession on your Activity .
It may not be what you are seeing, but on my phone, something like this happens because sleep mode is always in one orientation, and if the app was in the other one it gets killed and recreated in the sleep orientation... rather suboptimal if you ask me.
It sounds to me like you may not have things such as your startup sound tied to sufficiently specific causes. What happens if you rotate the phone while it's "on" ? At any rate, you should be able to detect that the screen is not on and not do (or defer) a real startup.
If an implicit orientation change is the culprit, you can change how your application is treated with these - set things to claim your application can change on the fly instead of having to be recreated.
In the activity's manifest, for each application add:
android:configChanges="orientation|keyboardHidden"
This tells android you'll handle these two cases yourself - although of course you're lying: you won't do shit to handle them, but Android doesn't know that. This works great for apps/games/etc running for example in landscape mode and never change orientation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With