Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass intent with extras to an already running activity

I have a BroadcastReceiver which launches a HomeActivity with some information passed with the extras.

What happens when the activity is already running and the broadcast receiver gets triggered again which tries to launch the HomeActivity with new info. Does the OnResume() or OnCreate() of the activity execute?

If not, is there any other way of passing/reloading a running activity when a BroadcastReceiver is triggered?

like image 621
Ayrton Senna Avatar asked Sep 07 '13 10:09

Ayrton Senna


People also ask

How do you pass an activity in intent?

The easiest way to do this would be to pass the session id to the signout activity in the Intent you're using to start the activity: Intent intent = new Intent(getBaseContext(), SignoutActivity. class); intent. putExtra("EXTRA_SESSION_ID", sessionId); startActivity(intent);

How can I pass value from one activity to another activity in Android without intent?

This example demonstrate about How to send data from one activity to another in Android without intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

Make sure when you are launching the intent from the BroadcastReceiver you set the FLAG_ACTIVITY_SINGLE_TOP flag.

intent.addFlags (FLAG_ACTIVITY_SINGLE_TOP);  ...   class HomeActivity extends Activity {    ...    @Override    protected void onNewIntent(Intent intent) {       Bundle extras = intent.getExtras();    }    ... } 
like image 113
Cory Roy Avatar answered Sep 20 '22 11:09

Cory Roy