CantThinkOfAnything
CantThinkOfAnything

Reputation: 1179

How do I clear the back history of my app only if user performs an action?

I am having trouble controlling the behaviour of Intent.

The use case is this: When a user is browsing the internet in Chrome and clicks on menu, share and then on my app, a screen opens allowing the user to edit certain information. When the user is done editing he or she can click on "Done, choose chat to post". Then a new activity opens with all the available chats.

At this point, the user should be able to press the standard back button to return to the editing activity or the user can click on a chat to post.

If the user clicks on a chat and posts the link, a new acitivity starts the chat allowing the user to continue chatting or press back to return to the browser and NOT to the "choose chat" activity or the "edit information" activity.

so basically i want to be able to do the following:

use case 1: [browser] --> [share] --> [edit info] --> [choose chat]. (back button returns to [edit info].

use case 2: [browser] --> [share] --> [edit info] --> [choose chat] --> [open chat] . (back button return to [browser].

I have tried various combinations of Intent flags when starting [edit info] and [choose chat] but none is giving me the behaviour that I am trying to achieve.

So my question is: How do I clear the back history of my app only, allowing the user to return to the previous app BUT ONLY when the user finishes the prescribed process (in this case, actually posting the link in a chat)?

Upvotes: 0

Views: 84

Answers (1)

Vincent Paing
Vincent Paing

Reputation: 2475

On creating the Activity for Open Chat, use this flag

Intent i = new Intent();
i.setClass(getActivity().getApplicationContext(), YourActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);

Upvotes: 1

Related Questions