Search code examples
androidandroid-activityoncreateonstart

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?


Solution

  • 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