You can create an intent with the intent.FLAG_ACTIVITY_CLEAR_TOP
flag from F to C. Then you will need to call startActivity () with the intent and call this to happen onBackPressed or something like that.
Intent i = new Intent(this, C.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(i)
See this answer, which also says that C will not restart when you return to it: fooobar.com/questions/542981 / ...
What FLAG_ACTIVITY_CLEAR_TOP
will do is return to the most recent instance of C activity on the stack and then clear everything above it. However, this can lead to the re-creation of activity. If you want to make sure that it will be the same activity instance, use FLAG_ACTIVITY_SINGLE_TOP
. From the documentation:
The currently executable instance of action B in the above example will either get a new intention, which you start here in your onNewIntent (), or it will be completed and restarted with a new intention. If he declared his startup mode "multiple" (default), and you did not set FLAG_ACTIVITY_SINGLE_TOP in the same intention, then it will be completed and recreated; for all other starts, or if FLAG_ACTIVITY_SINGLE_TOP is set, this intent will be delivered to the current instance of onNewIntent ().
Edit: Here is a sample code similar to what you want to do:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent a = new Intent(this, C.class); a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(a); return true; } return super.onKeyDown(keyCode, event); }
Source code example: fooobar.com/questions/89680 / ...
source share