0

I'm having a hard time managing a back button in my app. If I'm not mistaken, the back button default function should return the user to their previous activity. But when I'm changing from one activity to another I call finish() in the listener. Because of the killed previous activity, pressing back button causes the app to exit.

Is there any way to preserve the previous activity and kill it only after the current activity has changed?

BTW, I know how to override the back button. But if I have a lot of activities, is it efficient to write an override for every activity that doesn't have previous acvitity already killed? I'm developing an RPG and I'm pretty sure there will be a lot of activities.

glomad
  • 5,539
  • 2
  • 24
  • 38
iwalyfa
  • 49
  • 7
  • Based on what it sounds like you want to do, your best bet would be to start the previous activity again, but pass variables through its intent. – Andrew Schuster Oct 31 '13 at 15:25
  • any example how to do that?I know how to pass variable using intent.. but I don`t know how to restart/start the activity using the provided variables.. – iwalyfa Oct 31 '13 at 15:28
  • If I understand well, you should not let the default back button behavior go to the previous screen instead you want to save the state then restart the activity – meda Oct 31 '13 at 15:30

1 Answers1

0

You're setting yourself up for a really bad time. You want to use as few activities as possible. In a game you really don't want to manage all of that data going back and forward between * amount of activities.

You need models to manage the game data, and your view activity can receive this data from a view controller. You don't want to kill you main view activity and you don't want to keep a bunch of activities in memory. Read a few chapters from this book. Good luck!

http://danielrparente.files.wordpress.com/2013/01/rpg_design_patterns_9_26_05.pdf

Jason Cheladyn
  • 565
  • 1
  • 12
  • 24