I am trying to understand Android Activity lifecycle. For that purpose, I have created Activity where I have overridden all lifecycle methods(onCreate, onStart, onRestart, onResume, onPause, onStop, onDestroy):
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Log.d("ActivityTutorial", "onCreate");
}
@Override
protected void onStart() {
super.onStart();
Log.d("ActivityTutorial", "onStart");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("ActivityTutorial", "onRestart");
}
@Override
protected void onResume() {
super.onResume();
Log.d("ActivityTutorial", "onResume");
}
@Override
protected void onPause() {
super.onPause();
Log.d("ActivityTutorial", "onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.d("ActivityTutorial", "onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("ActivityTutorial", "onDestroy");
}
}
I put breakpoints on the lines where I am logging using Log.d(...). Then I tried to debug. onCreate method is okay - it is calling when activity is created.
Strange situation is starting onStart method. According to Android documentation: "onStart() Called when the activity is becoming visible to the user." But when I debug, it comes to onStart method but Button which is on this Activity, not visible yet.
I thought it supposed to be seen onResume() - after calling onStart() method. But button was not visible.
Only after onResume method, button was visible.
So my question is what is wrong with onStart and onResume methods? Maybe I am doing something not in the way it supposed to be done?