Android lifecycle: Fill in data in activity in onStart() or onResume()?

Posted by pjv on Stack Overflow See other posts from Stack Overflow or by pjv
Published on 2011-01-08T23:36:19Z Indexed on 2011/01/09 0:53 UTC
Read the original article Hit count: 162

Filed under:
|
|
|
|

Should you get data via a cursor and fill in the data on the screen, such as setting the window title, in onStart() or onResume()?

onStart() would seem the logical place because after onStart() the Activity can already be displayed, albeit in the background. Notably I was having a problem with a managed dialog that made me rethink this. If the user rotates the screen while the dialog is still open, onCreateDialog() and onPrepareDialog() are called between onStart() and onResume(). If the dialog needs to be based on the data you need to have the data before onResume().

If I'm correct about onStart() then why does the Notepad example give a bad example by doing it in onResume()? See http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html NoteEditor.java line 176 (title = mCursor.getString...).

Also, what if my Activity launches another Actvity/Dialog that changes the data my cursor is tracking. Even in the simplest case, does that mean that I have to manually update my previous screen (a listener for a dialog in the main activity), or alternatively that I have to register a ContentObserver, since I'm no longer updating the data in onResume() (though I could update it twice of course)?

I know it's a basic question but the dialog only recently, to my surprise, made me realize this.

© Stack Overflow or respective owner

Related posts about android

Related posts about dialog