Issue
Suppose there is a button on the homepage of my Activity.
When I press this button, it goes to Activity A
in Activity A , it automatically goes to Activity B using Intents and startActivityForResult();
in Activity B , it automatically goes to Activity C using Intents and startActivityForResul();
in Activity B, it automatically starts the intent to go BarCode scanner activity and get results.
My problem is when I press a button to return to my home page, it requires pressing 4 times go back to my homepage
If I want to press back to my homepage at one time, how to finish such series of activities?
Solution
Don't Use/override onBackPressed() anywhere in your program
just add the following method in the parent activity such as Activity A and B
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
Start Activity on your onClick method using
startActivityForResult(intentName, 0);
In Child Activity you use/override onStop() method
@Override
protected void onStop()
{
super.onStop();
}
Answered By - RajeshVijayakumar
Answer Checked By - Pedro (JavaFixing Volunteer)