in my App, I am launching the Facebook App using this code:
String uri = "fb://page/" + fbPageId;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
This is working as expected. But currently, when the user starts the FB activity and then presses the “Home”-button and starts my App again, he will see the Facebook App. The user has to press the “Back”-button to see my App. I don’t like this behaviour. This may be good for internal but not for external intents..
Is it possible to start the Activity and remove this new activity immediately from the current App’s stack?
If have also tried stuff like startActivityForResult(), but that did not do the trick.
This is so because both FB Activity and your Activity belong to same task. Refer to Official Documentation about how to launch an Activity in a separate task.
Specifically, the Intent Flag
FLAG_ACTIVITY_NEW_TASKis used to start an Activity in a separate task.