Yes it is possible. But in the case of 2 or more parents, you cannot rely on the implementation of Up Navigation, as described here: Providing navigation up
So, you have 2 options left:
1- Use the behavior of the back button
You can do this simply by calling finish() or onBackPressed() in your onOptionsItemSelected(MenuItem item) android.R.id.home . Like this:
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; }
2- Return to the first activity of your application
Return the user to the first activity your application starts with, for example:
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent backIntent = new Intent(this, YOUR_FIRST_ACTIVITY.class); backIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(backIntent); return true; }
By the way, this question is a possible duplicate of this question
source share