To solve some problems regarding App pause/resume, I tested the Activity Lifecycle by following simple App:
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
Log.w("xxx", "create");
}
@Override
public void onStart(){
super.onStart();
Log.w("xxx","start");
}
@Override
public void onResume(){
super.onResume();
Log.w("xxx","Resume");
}
@Override
public void onPause(){
super.onPause();
Log.w("xxx","pause");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.w("xxx","destroy");
}
@Override
public void onStop(){
super.onStop();
Log.w("xxx","stop");
}
@Override
public void onRestart(){
super.onRestart();
Log.w("xxx","restart");
}
}
with a simple layout containing a Textview.
I installed the app and ran it:
01-28 11:56:09.032 2517-2517/android.se.behy.test W/xxx: create
01-28 11:56:09.035 2517-2517/android.se.behy.test W/xxx: start
01-28 11:56:09.035 2517-2517/android.se.behy.test W/xxx: Resume
and turned the display off (by pushing the on/off button) and surprisingly saw the following log:
01-28 11:56:09.032 2517-2517/android.se.behy.test W/xxx: create
01-28 11:56:09.035 2517-2517/android.se.behy.test W/xxx: start
01-28 11:56:09.035 2517-2517/android.se.behy.test W/xxx: Resume
01-28 11:56:20.750 2517-2517/android.se.behy.test W/xxx: pause
01-28 11:56:20.753 2517-2517/android.se.behy.test W/xxx: stop
01-28 11:56:20.809 2517-2517/android.se.behy.test W/xxx: destroy
01-28 11:56:20.843 2517-2517/android.se.behy.test W/xxx: create
01-28 11:56:20.844 2517-2517/android.se.behy.test W/xxx: start
01-28 11:56:20.844 2517-2517/android.se.behy.test W/xxx: Resume
01-28 11:56:20.857 2517-2517/android.se.behy.test W/xxx: pause
Question
normally I expected just to pause the app when I turn the display off, but why stop, destroy, create, start, resume and pause after it?