Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Notepad example - Why populate in onCreate?

Tags:

android

I have finished the Layout exercise and wondering why they include the call to populateFields() in both onCreate and onResume.

According to Activity Lifecycle "onResume" will always be performed before the Activity is shown so why not just there?

like image 270
theblitz Avatar asked Apr 01 '11 08:04

theblitz


People also ask

What happens in the onCreate () callback method?

onCreate() You must implement this callback, which fires when the system first creates the activity. On activity creation, the activity enters the Created state. In the onCreate() method, you perform basic application startup logic that should happen only once for the entire life of the activity.

What is called after onCreate Android?

OnStart is always called by the system after OnCreate is finished. Activities may override this method if they need to perform any specific tasks right before an activity becomes visible such as refreshing current values of views within the activity. Android will call OnResume immediately after this method.

Why do we need to call setContentView () in onCreate () of activity class?

As onCreate() of an Activity is called only once, this is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.

What is the use of an onStop () function in Android?

The onStop() function is called when the application enters the stopped state. In this state, the activity is no longer visible to the user. This may happen for the following reasons, the user performing some action that invoked another activity to come to the foreground or the activity finished.


1 Answers

I have real production code that populates fields and is only called in onResume and it works just fine. I thought one reason would be that maybe onResume is called after the activity is shown, but a bit of googling digs this (mostly unrelated) thread: http://groups.google.com/group/android-developers/browse_thread/thread/ddea4830bedf8c6c?pli=1

Quote: onResume() is thus the last thing that happens before the UI is shown

This is what Dianne Hackborn says so i guess we can trust her :)

like image 69
Torp Avatar answered Sep 24 '22 20:09

Torp