1

I have developed an application and there are many activities in this project. In setting activity, I place one exit button, on click event of that exit button I want to exit whole application. So what should I do for that?

rmtheis
  • 5,992
  • 12
  • 61
  • 78
Ramesh Solanki
  • 373
  • 1
  • 5
  • 15

6 Answers6

1

if you are calling activity B from an activity A.and C from B

A->B

use startactivityforresult from A

and again B->C

use startactivityforresult from B

and when you want to exit from C then setResult(i.e. RESULT_OK) and finish C.and in OnActivityResult() in B,check if resultcode == RESULT_OK then again finish B and setresult(RESULT_OK) for A.same procedure will follow to finish A.

this will exit you from the application.and application will start from A not from C.

ankita gahoi
  • 1,532
  • 2
  • 15
  • 28
  • but there are lots of activity. so how can i handle whole project – Ramesh Solanki Mar 23 '11 at 06:53
  • actually android doesn't exit application,it handles from its own way,what we can do,exit from all application,by this process.else you can hide your application by launching home page. moveTaskToBack(true); – ankita gahoi Mar 23 '11 at 07:56
1

I think finish() is what you are looking for.

Ham Vocke
  • 2,942
  • 22
  • 27
0

Use this to end an Application System.exit(0);

Ndupza
  • 780
  • 1
  • 6
  • 16
0

As a bad example - u can create your own broadcast 'com.example.KILL_ACTIVITIES' and send it in onBackPressed method. So, all your activities must be registered to this broadcast and call finish() when receive that broadcast.

UAS
  • 405
  • 2
  • 4
  • 9
0

"Android" programs aren't supposed to have an EXIT button. See any app that comes pre-installed in your device and check if any of them actually have an EXIT button. Exit makes no sense. It just ends up giving a sense of false security to the user.

Anand Sainath
  • 1,807
  • 3
  • 22
  • 48
  • [More](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) like minded people here.. – Anand Sainath Mar 23 '11 at 17:24
0

Just write this code in your application

moveTaskToBack(true);

And you will be thrown out to main android desktop..

Bhavin2887
  • 170
  • 2
  • 3
  • 10