I've searched through dozens of Stackoverflow posts and the android doc but just couldn't find the answer.
According to the accepted answer of this SF-post the onCreate method runs when the activity is first created. It also notes that in here views are supposed to be created and list data is being binded.
Then the onStart Method runs but here's the issue. Where's the difference? If you do everything inside of onCreate, switch activities, your app will still display the same data, regardless whether you put the app in the background or switched activities.
So if you declare views in onCreate, what do you do in onStart? initiliaze the views to their R.id.view ? Fetch data?
onResume I suppose is then used for listeners since it's the gas and brake according to this SF-posts accepted answer.
onCreate()
is called when the activity is first created. onStart()
is called whenever the activity becomes visible, which includes when it is first created (after onCreate()
) and after it is coming back to the screen from being stopped (e.g., another activity took over the screen).
So:
Put code in onCreate()
that needs to happen when the activity is created (and use onDestroy()
to clean it up)
Put code in onStart()
that needs to happen either when the activity is created or when the activity returns to the foreground (and use onStop()
to clean it up)
Frequently, we do not do anything special when the activity returns to the foreground, in which case you do not need to worry about onStart()
or onStop()
.