0

I have two activities, say Activity A and Activity B. Activity A is created when the application starts and then Activity B is being called from Activity A as follows:

Intent i = new Intent(A.this, B.class);
startActivity(i);

Activity B loads a Thread on its onCreate() and then when you click on Back, it will return to Activity A. This Thread is loading some images from a Database that is being updated within Activity B as well.

How can I save the state of Activity B so that I can avoid reloading the Thread that I have in Activity B when I call it again from Activity A.

Erick
  • 1,247
  • 3
  • 15
  • 24

3 Answers3

0

Move the database loading to a separate class and load from there.

Kevin Parker
  • 16,975
  • 20
  • 76
  • 105
0

You may want to check this question: Saving Android Activity state using Save Instance State

But consider that, depending on how long the Activity A takes and how much memory the device has left, Activity B could be killed before it returns.

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • I have actually read that a while ago and tried implementing it but i got no luck.. :( – Erick Jun 03 '11 at 05:41
  • It seems that onSaveInstanceState() on Activity B is not being called. I think this is what this link:http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29 is trying to explain. – Erick Jun 03 '11 at 06:20
0

Create a singleton class which loads the images and caches them. Every time you launch Activity B check this singleton class for images. If not loaded then load them otherwise read from the cache

pankajagarwal
  • 13,462
  • 14
  • 54
  • 65
  • Thanks for the advice, can you show me some samples of a singleton class? – Erick Jun 03 '11 at 05:40
  • see this link for example of singleton class http://www.theserverside.com/discussions/thread.tss?thread_id=31650 move your loading thread in the constructor of this class – pankajagarwal Jun 03 '11 at 06:22