Reputation: 69
I have two activities: First activity: MainActivity.java
Intent intent = new Intent(MainActivity.this, ChildActivity.class);
.
.
.
startActivity(intent);
Second activity: ChildActivity.java
btnExit.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
//I wanna exit completely app in here, but i can't
System.exit(0);
}
});
I've tried a lot of way on StackOverFlow but it's not working. How can i solve my problem?
Upvotes: 0
Views: 94
Reputation: 595
start child activity using
startActivityForResult(Intent intent, int requestCode);
For closing child activity use setResult(RESULT_OK); finish();
in your child activity.
And when it is returned, use finish(); for the same requestCode in your parent activity:
@Override
onActivityResult(int requestCode, int resultCode, Intent intent){
if( requestCode == <yourRequestCode> && resultCode == RESULT_OK)
finish();
}
Upvotes: 1