Search code examples
androidandroid-intentactivity-lifecycleonpauseondestroy

Intent Flag doesn't work for physical button in android


I want to create a simple app which having two activities... And I want to jump one activity from another without performing OnDestroy(); I want there to happen OnPause();

I can achieve it by using a flah like below.

Intent intent = new Intent(secondActivity.this, firstSecond.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

But the flag only works on the BackButton Which is inside the current activity. If I click back button in my mobile the flag doesn't work..... what should I do???? any help??

Thanks in advance


Solution

  • Override onBackPressed() and execute the same code instead:

    Intent intent = new Intent(secondActivity.this, firstSecond.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);