Okay I'm sort of confused. I have two activities: Activity A and Activty B, I can navigate to B from A very easily. Once at B when I press the physical back button, Activity B dies and I'm right back where I left off at A. However, if instead I call onBackPressed(), Activity B dies but Activity A is created from scratch (onCreate() called).
I can understand that I can not rely on Activity A being kept alive etc. but pressing the back button works every time whereas onBackPressed() fails every time. I was under the assumption that onBackPressed and pressing the button did the same thing.
Appreciate all help!
Launching Activity B:
Intent i = new Intent(getActivity(), MailActivity.class);
Mail m = mMails.get(position);
i.putExtra(MailFragment.EXTRA_MAIL, m);
Log.d(TAG, "Mail Packed");
startActivity(i);
Trying to back to A from B:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
getActivity().onBackPressed();
return false;
default:
return super.onOptionsItemSelected(item);
}
}
You might want to look at the Intent flags you are sending when you do context.startActivity(intent);
You can set intent flags
intent.setFlags(FLAGS_GO_HERE | ANOTHER_FLAG_IF_YOU_WANTED);
More details: http://developer.android.com/guide/components/tasks-and-back-stack.html
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments