0

I just noticed a pretty large amounts of error in my code.

My app has quite a few pages (in the form of fragments) and a splash screen. The manifest is set up to load the splash screen and then start the mainactivity class.

When the mainactivity class loads up (after the splash screen) it shows the home page of the app, thats fine, but when i load up another fragment I always just assumed that if I hit the back button on the device it would take me back to the page opened before hand but instead of that it takes me back to the splash screen and traps me there.

Any help guys?

KiKMak
  • 828
  • 7
  • 27
CyberHydra
  • 87
  • 2
  • 2
  • 9
  • Have you overrridden the `onBackPressed` function? If so, have you included your call to `super.onBackPressed()`, or `finish()`? – Matt Clark Apr 05 '14 at 00:44

2 Answers2

2

After you launch the main activity from the splashscreen you should call finish() on the splashscreen to ensure that it will not show up again (after all, it will not be needed anymore, so why keep it alive?). Then you should override onBackPressed on your main activity and ensure that instead of calling super, and finishing the current activity, it will call your fragments adapter and change the current visible fragment.

tf.alves
  • 919
  • 8
  • 15
  • Cheers for the help this was the problem, I had left the splash screen alive and hadn't sorted out the `onBackPressed` method. – CyberHydra Apr 05 '14 at 01:37
0

You need to use addToBackStack functionaliy of fragmentTransaction

Take a look at docs and example

Community
  • 1
  • 1
tsobe
  • 179
  • 4
  • 14