·onRestart->onStart()->onResume()
·当Activity被遮挡:
·onPause()->onStop()MainActivity:
package com.example.activity_test; import android.location.GpsStatus.Listener; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity { private final String TAG = "Activity LifeCycle"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG, "MainActivity -> onCreate()"); InnerOnClickListener listener = new InnerOnClickListener(); findViewById(R.id.btn_SecondActivity).setOnClickListener(listener); findViewById(R.id.btn_Small).setOnClickListener(listener); } private class InnerOnClickListener implements OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_SecondActivity: startActivity(new Intent(getApplicationContext(),SecondActivity.class)); break; case R.id.btn_Small: startActivity(new Intent(getApplicationContext(),SmallActivity.class)); break; default: break; } } } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Log.d(TAG, "MainActivity -> onStart()"); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Log.d(TAG, "MainActivity -> onResume()"); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); Log.d(TAG, "MainActivity -> onRestart()"); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); Log.d(TAG, "MainActivity -> onPause()"); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); Log.d(TAG, "MainActivity -> onStop()"); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.d(TAG, "MainActivity -> onDestroy()"); } }
package com.example.activity_test; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; public class SecondActivity extends Activity { private final String TAG = "Activity LifeCycle"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); Log.e(TAG, "SecondActivity -> onCreate()"); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Log.e(TAG, "SecondActivity -> onStart()"); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Log.e(TAG, "SecondActivity -> onResume()"); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); Log.e(TAG, "SecondActivity -> onRestart()"); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); Log.e(TAG, "SecondActivity -> onPause()"); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); Log.e(TAG, "SecondActivity -> onStop()"); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.e(TAG, "SecondActivity -> onDestroy()"); } }
package com.example.activity_test; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; public class SmallActivity extends Activity { private final String TAG = "Activity LifeCycle"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_small); Log.i(TAG, "SmallActivity -> onCreate()"); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Log.i(TAG, "SmallActivity -> onStart()"); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Log.i(TAG, "SmallActivity -> onResume()"); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); Log.i(TAG, "SmallActivity -> onRestart() "); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); Log.i(TAG, "SmallActivity -> onPause()"); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); Log.i(TAG, "SmallActivity -> onStop()"); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.i(TAG, "SmallActivity -> onDestroy()"); } }