The reason an activity is destroyed and re-created is to run it with a new configuration. You haven't said all that much about what you are doing so it is hard to know what is going on, but I would assume that you have forced an orientation for your activity, and the lock screen has a different orientation. So when the device goes to sleep, the lock screen is displayed and forces an orientation and your activity (which is still running at the top of the activity stack) now needs to be restarted with the new orientation.
The first thing is -- your activity really just needs to work correctly when this happens. If it doesn't, then you will see these same bugs in other cases. For example if the user plugs in a keyboard causing a config change. Or changes the locale. Or font size. And on and on. Now assuming your activity is actually working correctly, if there is a kind of config change you really don't care about you can use android:configChanges in your activity in the manifest to say it should not be restarted when specific kinds of changes happen. On Fri, May 13, 2011 at 2:19 AM, Jump <[email protected]> wrote: > I am familiar with the activity lifecycle. To make myself clear. I am > finding the behavior strange in this case. > > 1. Running the app then bringing it to the background by pressing home and > then pushing the lock button does not destroy my activity. > 2. Running the app then pushing the lock button destroys my activity and > then instantly creates it again. > > Doing (1) i can get the app to run in the background while device is locked > without it being destroyed, but doing (2) I cannot. Seems strange to destroy > the activity and then instantly create it again. > > Doing (2) with Angry Birds does not destroy the activity, it leaves it as > it is. Because when you go back to the game it runs instantly, no texture > loading or anything. The music is not running in a service. And the music > does stop when going to the background via the home button (1), so that's > why I was thinking it had something to do with that. > > > Anyway, thank you for any hints. > > > > > > > > Den fredagen den 13:e maj 2011 kl. 01:01:48 UTC+2 skrev MagouyaWare: >> >> *> When I run my game app and then push the sleep/lock-screen button my >> activity is destroyed (onDestroy is called) and then directly after, >> onCreate is called.* >> * >> * >> Welcome to the Android Activity Lifecycle... You have no control over >> it... >> * >> * >> *> Angry Birds actually keeps the music running when the lock screen is >> on, maybe there's some trick with that you can use?* >> >> Obviously I don't know for sure, but Angry Birds is probably playing its >> music in a Service... Which is different than keeping the app alive. >> >> *> I do not want to handle state.* >> * >> * >> Good luck... That is how Android handles this. >> *** >> * Thanks, >> Justin Anderson >> MagouyaWare Developer >> http://sites.google.com/site/magouyaware >> >> >> On Tue, May 10, 2011 at 8:00 AM, Jump <[email protected]> wrote: >> >>> I do not want to handle state >> >> >> -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

