I have 3 activities. Activity A which leads to activity B, which in turn can go back to activity A or start activity C. However, if I press back in activity C the app should
You shou use onActivityResult method in your parent Activity
Suppose Activity A is parent of Activity B. If you want to click back button in Activity B to exit Application (also exit Activity A)
In your Activity B, in onStop()
or onDestroy()
you call
setResult(0); //any int number is fine
this will pass a result code to its parent activity.
Your parent Actvity A, listens for the result code
you will need to use onActivityResult
method
inside the method you can call
if(resultCode == 0) //matches the result code passed from B
{
ActivityA.this.finish()
}
It works for me :)