Android Development Learning Diary Day (2)

A, Activity Introduction

1, Activity Overview

  Activity is a phone or tablet in one screen is divided into four states:

  Run: When the main application screen.

  Pause: Click to exit the residence at the exit the dialog.

  Stop: Click OK to exit.

  Destruction: Background destroyed when the application is stopped.

 There are seven methods:

  onCreate (): Called when the activity is first created.

  onStart (): Called when the user interface becomes visible. If the activity into the foreground, then follow the implementation of onResume () method, if hidden, execution onStop ().

  onResume (): Called when the user interface becomes visible. At this point, Activity has been seen, and appears in the foreground and the event begins. Note that onStart () is executed when the Activity is displayed in the background, only when onResume () is executed when the Activity was displayed to the foreground.

  onPause (): onPause () method is called when the system is about to begin before the display interface. If the interface is returned to the front desk, then follow onResume (); if invisible to the user, use onStop (). After the onPause () method performs, Activity switched daemon interface.

  onStop (): onStop () method will be called when the user interface is no longer visible, because another screen is displayed and go to cover this interface. This may be because the interface is a new beginning, the other interface will be displayed as a front-end interface, or the interface is being destroyed. If the interface is fast echo user interaction and followed onRestart () will be executed, otherwise, the interface back to the destruction of onDestroy () method will be executed.

  onRestart (): after you stop calling interface, and then start again, always follow onStart ().

  onDestroy (): method before your interface is destroyed by the last call.

  Activity life cycle:

 Test the following code:

@Override 
    protected void the onCreate (the Bundle savedInstanceState) { 
        Super .onCreate (savedInstanceState); 
        the setContentView (R.layout.activity_main); 
        Log.i ( "life cycle of the Activity", "onCreate () method calls" );  }  @Override  protected void onRestart () {  Super .onRestart (); Log.i ( "life cycle of the Activity", "onRestart () method calls" );} protected void @Override the onPause () {Super .onPause (); Log.i ( "the Activity life cycle "," onPause () method calls " );} protected void @Override onDestroy () {Super .onDestroy (); Log.i (" life cycle of the Activity "," onDestroy () method calls " );} @Override protected void onStart() { super.onStart (); Log.i ( "Activity life cycle", "the onStart () method calls" );} protected void @Override onStop () {Super .onStop (); Log.i ( "the Activity life cycle", " onStop () method calls " );} protected void @Override onResume () {Super .onResume (); Log.i (" life cycle of the Activity "," onResume () method calls " );

  AndroidStudio operation and open Logcat View:

  Click when app:

 

 

    When click another message pop:

 

 

    When you press the return key to return app:

 

 

    When the lock screen:

 

 

    Unlock:

 

 

    When you click the button recent tasks:

 

 

    Then back to the desktop: no method is called

  Back app when:

 

 

   Click the button to exit or the recent mission crossed out app hits:

Guess you like

Origin www.cnblogs.com/liblogs/p/11447668.html