Android: Determine when an app is being finalized vs destroyed for screen orientation change

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-03-20T02:49:16Z Indexed on 2010/03/20 2:51 UTC
Read the original article Hit count: 506

Filed under:
|

Hi all, I am relatively new to the Android world and am having some difficultly understanding how the whole screen orientation cycle works. I understand that when the orientation changes from portrait to landscape or vice versa the activity is destroyed and then re-created. Thus all the code in the onCreate function will run again. So here's my situation: I have an app that I am working on where it logs into a website, retrieves data, and displays it to the user. While this is all done in background threads, the code that starts these threads is in the onCreate function. Now, the problem lies in that whenever the user changes the screen orientation, the app will log in, retrieve the data, and display it to the user again. What I would like to do is set a boolean that tells the app if it is logged in or not so it knows whether or not it must log in when the onCreate function is called. So long as the app is in memory the HttpClient will exist and contain the cookies from logging the user in but when the app is killed by the system those will go away. So I would assume that I need to do something like setting the logged in boolean to false when the app is killed but since onDestroy is called when the screen is rotated how is this possible? I also looked into the finalize function and isFinishing() but those seem to not be working.

Shorter version: How can I distinguish between when an app is being killed from memory from when an activity is being rotated and different code for each event?

Any help or a point in the right direction is greatly appreciated. Thank you!

© Stack Overflow or respective owner

Related posts about android

Related posts about screen-orientation