Jyosna
Jyosna

Reputation: 4446

android how to force stop an application on button click

I have an application where many activities are there. I want in one activity's button click the application should be stopped( stopped in background). How can i do that? Thank you

Upvotes: 1

Views: 2095

Answers (3)

Mykhailo Gaidai
Mykhailo Gaidai

Reputation: 3160

The most straight way

System.exit(1);

:)

Upvotes: 1

ihrupin
ihrupin

Reputation: 6972

Best practice is to just call finish() and let the OS take care of killing off your process when/if it needs to.

Upvotes: 1

ankita gahoi
ankita gahoi

Reputation: 1562

Application can not stopped in background through programming.if you want to exit application or want to finish all activities-

use this-

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.

Upvotes: 0

Related Questions