Getting Started with Android.Activity Lifecycle 2

what is life cycle


Just like people, in childhood (sleeping, eating, playing), teenagers (sleeping, eating, studying), and adults (working, getting married), they all have to do what they need to do at this stage.


Activity, from creation to destruction, what is done in the middle, this is its life cycle


Those life cycle functions onCreate, onStart are completely called by the Android operating system itself, not by the programmers themselves


==================



a boring example


Lifecycles come in pairs:
onCreat,onDestory
onStart,onStop
onResume,onPause



public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.println("Buy a car");
    }


    @Override
	protected void onStart() {
		super.onStart();
		System.out.println("打火");
	}


	@Override
	protected void onRestart() {
		super.onRestart();
	}


	@Override
	protected void onResume() {
		super.onResume();
		System.out.println("Step on the accelerator");
	}


	@Override
	protected void onPause() {
		super.onPause();
		System.out.println("Release the accelerator");
	}


	@Override
	protected void onStop() {
		super.onStop();
		System.out.println("Turn off, stop");
	}


	@Override
	protected void onDestroy() {
		super.onDestroy ();
		System.out.println("Destroy the vehicle");
	}




Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327011231&siteId=291194637