0

I have Build a Simple app with a Home Activity and an Activity Drawer and some fragment tabs, What i could not understand is how to make the app resume from the last activity or the fragment since the user clicked the return button on his phone !

I know it is about onPause and onResume , but i couldn't understand how to implement these methods on my code !

2 Answers2

0

if you want to handle onResume and onPause Methods in your Activity you should override onResume and onPause methods in your java class like this :

@Override
public void onResume(){
super.onResume();
//TODO: put your own code to handle onResume event!
}

@Override
public void onPause(){
super.onPause();
//TODO: put your own code to handle onPause event!
}
Ali Soleimani
  • 301
  • 1
  • 4
  • 16
  • Exactly but i was wondering what kind of code i should put here ?! for Example my main activity just launches different fragments when the user click their buttons , So if the user clicked the return button on his phone ? what should i put there to make him come back to the exact same fragment ?! – Oussama Benzita Aug 29 '16 at 10:45
  • i you use tab layout in your main activity you should handle the viewpager current item! for example if you want when the user clicks back button you show him(her) first tab, you should put this code in your onBackPressed method like this: `@Override public void onBackPressed(){ super.this; veiwPager.setCurrentItem(0); }` – Ali Soleimani Aug 29 '16 at 12:24
0

I think you mean this: You need to add the activities or fragments to the (back)stack.

see: https://developer.android.com/training/implementing-navigation/temporal.html

Riddim
  • 143
  • 1
  • 8