简体   繁体   中英

Android - is onStart() called immediately after onCreate()?

If I have two activities A and B. And I create an intent that initiates activity B from the onCreate() of activity A, when will the onStart() of activity A be called?

For example, let us say I had the following:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = new Intent(this, B.class);
    startActivityForResult(intent, REQUEST_CONNECT_DEVICE);
}

Will the onStart() method of that activity be called as soon as these lines of code finish executing or will it create activity B first?

Work Flow

Basic Android Activity Life Cycle

When App opened : onCreated() > onStart() > onResume()

When App close : onPause()

Here in your case below is the work flow

Action 1: Activity A opened

  • onCreate() of Activity A called

Action 2 : Activity B started

  • onStart() of Activity A called
  • onResume() of Activity A called
  • onPause() of Activity A called

  • onCreate() of Activity B called

  • onStart() of Activity B called
  • onResume() of Activity B called

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM