pulancheck1988
pulancheck1988

Reputation: 2064

Intent to start activity - but don't bring to front

Description:

Code:

Intent I2= new Intent(context, MyActivity.class); 
I2.putExtra(..
I2.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); // | Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(I2);

Note: I added no "android:taskAffinity" to manifest.. i thought you should know

Upvotes: 39

Views: 37261

Answers (3)

David Wasser
David Wasser

Reputation: 95578

You don't want to start an Activity in the background. There are better ways to do what you want. You can have your Activity register to receive the broadcast Intent, for example. It will get the call to onReceive() even if it is in the background. You can determine if your Activity is in the background by setting a variable to true in onPause() and to false in onResume(). Then in onReceive(), if the variable is true you are in the background.

Upvotes: 5

Anand M Joseph
Anand M Joseph

Reputation: 885

You can use this line in your onCreate() method:

moveTaskToBack(true);

Upvotes: 7

vipin
vipin

Reputation: 3001

if you want your activity to be in background add this line in the oncreate of activity

moveTaskToBack(true);

Upvotes: 15

Related Questions