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?
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);
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.
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(); } ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With