I have a broadcast receiver which I want to pass onto an activity but if and only if the activity is visible. I don't want to start it up unless its already visible. Is there an option for this? Or a way to pass it but not have the activity become visible? Or if you know a way for an activity be register as a broadcast receiver that would work too I suppose.
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.
For this, Intent will start and the following methods will run: putExtra() method is used for sending the data, data in key-value pair key is variable name and value can be Int, String, Float, etc. getStringExtra() method is for getting the data(key) that is sent by the above method.
launchMode — singleTask | flag — FLAG_ACTIVITY_NEW_TASK: If an Activity do not exist in an already created Task, then it starts the Activity in a new Task with Activity's new instance at the root of the Task's back stack, else the Task is brought forward with the Activity's last state restored and this Activity ...
I think you can archive this by registering the Receiver in the onResume() and unregister the receiver in the onPause() method. This should do the trick.
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