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.
Asked
Active
Viewed 864 times
0
-
Please check this link might be helpful you 1) https://stackoverflow.com/a/9151209/7589424 2) https://stackoverflow.com/a/7687602/7589424 – Sagar Jethva Dec 02 '17 at 08:19
-
Better to use Fragment in here check this out https://stackoverflow.com/a/37653673/5792379 – Alimov Shohrukh Dec 02 '17 at 10:00
2 Answers
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);
}

Gaurav Naik
- 11
- 2