4

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?

John Doe
  • 397
  • 3
  • 18
  • 1
    You can easily find out by adding some logging. – Emmanuel Nov 26 '16 at 23:36
  • Does Activity A even get a chance to start when it's immediately pushed to background by Activity B? What if Activity B is translucent? There is a lot of cases. Build it in a way that you're independent on concrete order of events. Don't manufacture artificial problems. – Eugen Pechanec Nov 27 '16 at 00:33

1 Answers1

2

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
Jayakrishnan
  • 4,457
  • 29
  • 29