0

Background:

My app (I will call it "A") can be started from an intent. If a specific URL is clicked A is opened.

A has a custom navigation, so the back button does not always override super.onBackPressed() or finish() it.

The problem:

After opening A from another app lets say the email app (I will call it "E"), A can not come back to E. If I click the "tasks" button, where the user can see the name, icon, and a thumbnail of the current running apps, I can see that E (icon and name) has as thumbnail A, not E. When I click on it I go to A, and cannot come back to E.

The question:

Is there a way to come back to E from A? Should I track the activity stack to come back to it whenever I want? I know that I can not force close an application, but could I open the A from E closing E before A is open? Is there a way to specify this behaviour on the intent?

Thanks in advance.

Hugo Matilla
  • 1,304
  • 2
  • 13
  • 15
  • You just need to finish() your Activity...What exactly is the problem? (and fyi: I don't think it's a good idea to have 'custom navigation' that overrides the back function...it's a very bad experience for the user! Because it's expected to go back to the last activity (E) by pressing back... – jpm Nov 11 '13 at 11:08
  • Thank you @jpm the problem is that I connect *E* with *A*, so the user can do some actions in *A* and come back to *E*. This actions have some logic that must override the back button. There is DetailActivity after it a SelectionActivity and afterwards a ConfirmationActivity, In ConfirmationActivity the user is not supposed to come back to the SelectionActivity, actually in this specific case that would be a bad user experience, but coming back to the DetailActivity. I am thinking if there is a way to say in the intent (Manifest) to "forget the past activities" before launching the new one. – Hugo Matilla Nov 11 '13 at 11:18
  • Mh ok, I think I still don't really get the use case. However to forget the past activities you should take a look at the FLAGS you can pass to intents such as http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK . Maybe one is helpful for you... Also, to communicate with the calling Activity you can use setResult in your activity. Of course this is dependent on how onActivityResult is handled in the calling Activity/App... – jpm Nov 11 '13 at 11:30
  • I did not find the proper way, but I fixed it tracking in *A* when I was coming from *E*, and in that case use finish to come back to *E*. I still wanted to know how could I start *A* from *E* keeping them not connected. Hope someone has the answer :) Thank you @jpm for the help. – Hugo Matilla Nov 12 '13 at 11:16

1 Answers1

0

I found a solution that is working.

I check if the Activity of A comes from E, in this case I clear the Activity Stack and relaunch A.

if(comesFromE()){
    Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    finish();
}

This answer helped me: howto programatically “restart” android app?

Community
  • 1
  • 1
Hugo Matilla
  • 1,304
  • 2
  • 13
  • 15