Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Pass Intent to Activity only if activity is already active?

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.

like image 440
Androider Avatar asked Feb 17 '11 08:02

Androider


People also ask

How do you pass data between activities in android using 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.

How do you pass data from one activity to another activity using intent?

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.

What is intent Flag_activity_new_task?

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 ...


1 Answers

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.

like image 83
Flo Avatar answered Sep 18 '22 05:09

Flo