0

I wanted to create view like what's app call page. If I use other fragments or activity this page should not destroy. If I destroy activity by pressing some button then only it should call destroy function. I am not understanding how this feature is working. For this feature should I use Activity or fragment or something else.

Goku
  • 9,102
  • 8
  • 50
  • 81
meuser07
  • 368
  • 4
  • 10

2 Answers2

0

You can try to handle back navigation by yourself.

Override activity's method onBackPressed() and don't call super.onBackPressed() in it. In this case Activity.finish() won't be called and Activity won't be destroyed. You can start other Fragment or Activity in this callback instead if you wish, or return to the first page of the ViewPager(presumably) the way WhatsApp does.

Exapmle:

@Override
void onBackPressed() {
    // No super.onBackPressed() here!!
    Intent intent = new Intent(this, OtherActivity.class);
    startActivity(intent)
}
Daniil
  • 1,290
  • 11
  • 17
0

Don't Called finish() onBackPressed method called Intent

@Override
public void onBackPressed() {
    Intent home = new Intent(getApplicationContext(),HomeActivity.class);
    startActivity(home);
}