I have an activity A that starts activity B. When I press back button in my device, the onCreate()
method of activity B is called so I need to press back button 2 or more times to finish it. I have no idea why?!
I also tried using onBackPressed()
and onOptionsItemSelected()
in activity B to finish it, but that didn't work!!
I really appreciate your help =)
Try this one:
Intent i = new Intent(OldActivity.this, NewActivity.class);
// clear all activities from back stack
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
try to use intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); when you starting your activity B.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.