107-ADT18 Managing App Life Cycle
This tutorial is based on http://developer.android.com/training/basics/activity-lifecycle/index.html .
Give a name Life Cycle Test.
Replace the initial codes with the following codes…
package com.example.lifecycletest; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.widget.Toast; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tToast("onCreate"); } public void onStart() { super.onStart(); tToast("onStart"); } public void onRestart() { super.onRestart(); tToast("onRestart"); } public void onResume() { super.onResume(); tToast("onResume"); } public void onPause() { super.onPause(); tToast("onPause: bye bye!"); } public void onStop() { super.onStop(); tToast("onStop."); } public void onDestroy() { super.onStop(); tToast("onDestroy."); } private void tToast(String s) { Context context = getApplicationContext(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, s, duration); toast.show(); } } |
Add codes to output log message labeled with “lifecycle”.
(refer tutorial http://android-steps.blogspot.com/2014/12/105-adt-18-build-android-simple-user.html )