0

I have three activities (a, b, c).

Activity a - has one button for activity b and one button to close the app (by calling onfinish()). - is the main activity, which runs b. Activity b - is the middle one which runs c.

After clicking on a back button that I placed in the header of activity c, and then clicking on the button of the a activity to close the app, I am returned to activity c. This is not the behavior I expected, any ideas about what is happening?

Further information:

  1. activity c has onResume() because I also have an activity d. so when I click back button of activity d, it returns to activity c.

  2. so long as I don't run the activity c, the close button works as expected.

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
  • 1
    Seems like you got a bad understanding of basic android navigation and activity/intents: an Android application does not really "closes", your just terminate an `Activity` using `finish()` and not `onfinish()`, the back button simply finishes the current `Activity` and brings back the last one. Also check your `Intent` flags. – shkschneider Jan 12 '15 at 13:30
  • I know very well that the app is still running even after 'closing' it. Also onfinish() was a typo, otherwise I'dnt make this question. Anjali with his answer shows how to finish my application, thanks anyways! – Nikos Pappas Jan 12 '15 at 13:36

2 Answers2

1

For going previous activity just call

finish() ;

at back button of any activity .don't do this

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

and from exiting the application use

Intent intent = new Intent(getApplicationContext(), a.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
K Guru
  • 1,292
  • 2
  • 17
  • 36
1

try this.

Intent intent = new Intent(getApplicationContext() or UrActivity.this, FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
M S Gadag
  • 2,057
  • 1
  • 12
  • 15