Reputation: 39
I am new to android and java.I have created 9 activities(screens) and each one has a next button to navigate to next screen and 9th screen has an exit button to close the application.but if i call finish() or android.os.process.killProcess api's it is going to the previous screen but its not closing the whole application.
Could you please provide me the code snippet to close the whole application.
Upvotes: 3
Views: 169
Reputation: 35651
Use one activity and add fragments to it.
http://developer.android.com/guide/topics/fundamentals/fragments.html
Upvotes: 0
Reputation: 67296
If you don't want to come back to your previous Activities then finish()
every Activity before starting the new Activity.
Intent intent = new Intent(this, Second.class);
startActivity(intent);
finish();
Second option is to use startActivityForResult()
in every Activity and setResult()
in the last Activity that performs a call back onActivityResult()
to all the previous Activities to finish()
.
int AnyNumber = 123;
Intent intent = new Intent(this, Second.class);
startActivityForResult(intent, AnyNumber);
override onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == MyRequestCode){
if(resultCode == Activity.RESULT_OK){
finish();
}
}
}
Do this in every Activity and in the 9th Activity set the Result,
setResult(Activity.RESULT_OK);
This will call back and all the Activities will finish depending on the requestCode
.
Upvotes: 2
Reputation: 2020
in main Activity:
android.os.Process.killProcess(android.os.Process.myPid());
Upvotes: 0