Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Description:

  • Activity A is visible (or in the background)
  • Intent I is received by a broadcast with valuable extras and then passes the extras to a new Intent I2 that will be used to start activity A.
  • Outcome: Do not bring activity to front if activity is in background.

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

like image 946
pulancheck1988 Avatar asked Apr 04 '12 09:04

pulancheck1988


People also ask

Which type of intent should we use to start an activity?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.

How do you pass Intent between activities?

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.

What is the intent of an activity?

An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity() . The Intent describes the activity to start and carries any necessary data.

How do you launch an activity only once for the first time?

It is important to check that the first activity which opens when the app is launched is MainActivity. java (The activity which we want to appear only once). For this, open the AndroidManifest. xml file and ensure that we have the intent-filter tag inside the activity tag that should appear just once.


1 Answers

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

moveTaskToBack(true); 
like image 194
vipin Avatar answered Sep 19 '22 15:09

vipin