0

After processed some activity, i want to exit the application.I implemented

 public void onBackPressed() {
       System.exit (0);
}

But my application is back to previous activity..I need exit my application completely.How to do that? I had searching a lot of article but it not working on that. My android is 2.3

Jean_n
  • 45
  • 1
  • 3
  • 10
  • what happens if you call `finish()` instead? – dldnh Mar 16 '12 at 22:52
  • it also will go back previous activity – Jean_n Mar 16 '12 at 22:55
  • See [Quitting an application - is that frowned upon?](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) – CommonsWare Mar 16 '12 at 22:57
  • 1
    if you start your activity with `startActivityForResult` your first activity can detect when the second has finished and optionally the first activity can then finish itself. – dldnh Mar 16 '12 at 22:57

1 Answers1

5

dldnh is right. You can monitor for finish, or you can finish first activity after you start second activity.

{
     Intent i = new Intent(this, com.second.class)
     startActivity(i);
     this.finish();
}

then in secound activity:

public void onBackPressed() {
       this.finish();
}
bajicdusko
  • 1,630
  • 1
  • 17
  • 32