Which activity method is called when orientation changes occur?

前端 未结 2 861
独厮守ぢ
独厮守ぢ 2020-12-08 04:44

Which method of the lifecycle is called when orientation changes occur? My application executes the onResume() method or maybe reloads the whole activity becau

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 05:09

    public class MainActivity extends AppCompatActivity {
    private final static String TAG = "AppActivity";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate(Bundle) called");
        setContentView(R.layout.activity_main);
    }
    
    @Override
    public void onStart() {
        super.onStart();
        Log.d(TAG, "onStart() called");
    }
    
    @Override
    public void onPause() {
        super.onPause();
        Log.d(TAG, "onPause() called");
    }
    
    @Override
    public void onResume() {
        super.onResume();
        Log.d(TAG, "onResume() called");
    }
    
    @Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, "onStop() called");
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy() called");
    }
    

    }

    1) Try to run your app on your phone and/or emulator and open the Logcat => on top of the window select Verbose.

    2) Now try to change the screen orientation (ex. from portrait => landscape mode).

    I hope this alternative will give you more insight into the activity lifecycle.

提交回复
热议问题