How to get Intent of main launch Activity from a d

2019-04-10 05:44发布

问题:

I'm currently in a different Activity. How can I get the main launch Activity's Intent?

Intent launchIntent = getIntent();

In the above, obviously getIntent() would not get me the correct Intent that I need.

How can I get the main launch Activity's Intent?

回答1:

import android.os.Bundle;

Bundle extras = getIntent().getExtras();
   if (extras != null) {
       pics = extras.getInt(KEY_HERE);
   }

Replace pics and getInt as needed.



回答2:

When Activity1 loads, grab the Bundle associated with it's launch.

When Activity2 is launched, put these same extras into your new Intent, and pass it on to Activity2.

You can't just access an Intent from a different activity, you need to pass the information along.