[android-developers] Re: data between activities

2009-07-01 Thread Mike Hearn

It depends on the behavior you want.

Remember that Android multi-tasks. At any time, the user can go away
and do something else, then return to your app later. In between, your
process can be killed.

Thus if you stuff some objects into a static variable, you have to be
able to handle that variable being null when your activity is started.

If you stick that state into the intent, then the system will take
care of saving this data and loading it again when necessary. So, it's
convenient to put things here which control, for instance, what the
user will see. Some things can't be serialized like that, for instance
a thread. Then you have to handle reconstructing them when necessary
yourself.

A cache of bitmaps makes sense to stick in a static field, as long as
you can rebuild it when it goes missing. User-provided data doesn't
make any sense to put in a static field. You need to save that to a
database or a file.

Imagine you are writing a notes app. The user has 10 slots and each
slot can contain some text. When the user presses slot 3, they can
edit that slots text. In this case, you would store:

 - the text of each note in a database
 - the note that the user pressed in the intents extras
 - you can keep around a cache of the loaded notes in an ArrayList of
SoftReferences, stuffed in a static field if you want

It wouldn't make sense to keep the slot the user is editing in a
static field, because then when your Edit Note activity is restarted
after the process is killed it'll be zero. Put that data in the Intent
instead.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: data between activities

2009-06-30 Thread Saurav Mukherjee
if both the activities are in the same app, yes, its possible.

On Tue, Jun 30, 2009 at 12:47 PM, Sukitha Udugamasooriya
suk...@gmail.comwrote:


 Is it possible to transfer data between activities without using
 extars??
  I need to access MyOwnObject in Atctivity 1 from Activity2
  Possible with using static fields?


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: data between activities

2009-06-30 Thread Gavin Aiken
Yeah, I use an Application class which holds common data. There are a few
options;

http://developer.android.com/guide/appendix/faq/framework.html#3


On Tue, Jun 30, 2009 at 8:26 AM, Saurav Mukherjee 
to.saurav.mukher...@gmail.com wrote:

 if both the activities are in the same app, yes, its possible.


 On Tue, Jun 30, 2009 at 12:47 PM, Sukitha Udugamasooriya suk...@gmail.com
  wrote:


 Is it possible to transfer data between activities without using
 extars??
  I need to access MyOwnObject in Atctivity 1 from Activity2
  Possible with using static fields?





 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: data between activities

2009-06-30 Thread Dexter's Brain

Perhaps, passing data within activities is supposed to be done through
Bundles. I guess, that is why they are there...

Dexter.

On Jun 30, 3:21 pm, Gavin Aiken gavin.ai...@imperial.ac.uk wrote:
 Yeah, I use an Application class which holds common data. There are a few
 options;

 http://developer.android.com/guide/appendix/faq/framework.html#3

 On Tue, Jun 30, 2009 at 8:26 AM, Saurav Mukherjee 

 to.saurav.mukher...@gmail.com wrote:
  if both the activities are in the same app, yes, its possible.

  On Tue, Jun 30, 2009 at 12:47 PM, Sukitha Udugamasooriya suk...@gmail.com
   wrote:

  Is it possible to transfer data between activities without using
  extars??
   I need to access MyOwnObject in Atctivity 1 from Activity2
   Possible with using static fields?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---