Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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);

...


classHomeActivityextendsActivity {
   ...
   @OverrideprotectedvoidonNewIntent(Intent intent) {
      Bundleextras= intent.getExtras();
   }
   ...
}

Solution 2:

Just extending Cory Roy's answer you have to define "SingleTop" in AndroidManifest.xml too.

<activity
        android:name="MainActivity"            
        android:launchMode="singleTop"

It seems that extending android.support.v7.app.ActionBarActivity this method does not work...

Post a Comment for "How To Pass Intent With Extras To An Already Running Activity"