0
votes

I have this code inside a service:

PackageManager pm = app.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(app.getPackageName());

intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

app.startActivity(intent);

And this opens the app on top of task stack. I would like to know if is possible to start the app on the low, on background. That if you press the task manager button on the phone it displays the app. Is there a way?

Thanks

1
What exactly you are trying to do? - Rahul Raina
try by adding New Task flag in intent. - Sohail Zahid
Hi @SohailZahid I already have the New Task flag on my Intent: line 5. - Carlos Zinato
Hi @RahulRaina, the way my code works now, it opens the app on top of tasks, making it the active app, doesn't matter what app user is using. I don't like this, I prefer that if opens on the background, so users can switch to it later - Carlos Zinato
oh sorry i haven't see .... is there any info in logs? - Sohail Zahid

1 Answers

1
votes

No. But you could have the app send itself immediately to the background in the onCreate() of the first Activity like this:

moveTaskToBack(true);