Hi,

I also have a basic problem? How could I share a object reference,
e.g., a class instance, between two activities. In the Bundle's member
methods, no method support putting object reference.

Thanks

On Feb 15, 10:57 pm, Tote <[email protected]> wrote:
> Typically you call your current activity's startActivity() method to
> switch to another activity. That method can accept an instance of
> Intent class, which in turn enables you to put some data in the intent
> object before you call startActivity. Check out the documentation of
> Bundle class and you'll see that it's got a lot of put... methods (and
> the corresponding get... methods, too). So for example you could call
> putIntArray method which adds an int array to the bundle. E.g.:
>
> int[] ia = {1, 2, 3};
>
> Intent i = new Intent();
> Bundle b = i.getExtras();
> b.putIntArray("myIntArray", ia);
> startActivity(i, MyActivity2.class);
>
> Similarly, on the receiving end you can use getIntArray to get your
> data. The disadvantage of this solution is that whenever the data
> changes on one end you've got to update the other end, too, because it
> doesn't happen automatically.
>
> Another approach would be to use a singleton to store information that
> shall survive activity changes. In this case both ends access the same
> information and since no two activities can live at the same time you
> don't even need to bother with synchronization issues.
>
> On Feb 15, 11:58 am, madcoder <[email protected]> wrote:
>
> > Could you give a more detailed example - I too would like to see how
> > an array (of ints, for example) can be accessed in activity 2 from
> > activity one.  As it is now, I'm loading that data every time I start
> > a new activity - and it's quite slow!
>
> > Thanks
>
> > On Feb 14, 7:32 pm, Ganesan V <[email protected]> wrote:
>
> > > U can use Indent class of MyActivity from MyActivity2.
>
> > > Ganesh.
>
> > > On Sat, Feb 14, 2009 at 2:05 AM, Alex55 <[email protected]> wrote:
>
> > > > Hello guys,
>
> > > > I have a very basic question regarding Activities in Android.
>
> > > > Can I share data types a cross Activities in Android?
>
> > > > Let's say I have 2 activities, MyActivity.java and MyActivity2.java. I
> > > > have declared some Strings and Arrays on MyActivity that I would like
> > > > to access from MyActivity2, is this possible? If so, how can I
> > > > accomplish this?
>
> > > > I know its a very basic question, but believe it or not I've had a
> > > > hard time figuring this one out!
>
> > > > Many thanks for your prompt response,
>
> > > > Alex
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to