> I need to access the instance of the caller activity from the called
> activity. Mi application uses two screens (then, two activities) and
> when the second activity is instantiated, this instance has to access
> the instance of the first activity created so accessing its member
> functions and variables. I can't find a solution for this. Help is
> appreciated.

For the purposes of this email, I'll call your first activity "Activity A"
and the second activity "Activity B".

If you launch Activity B from Activity A via startSubActivity(), you can
arrange to pass data back when Activity B wraps up its work. Take a look
at the "Starting Activities and Getting Results" section of:

http://code.google.com/android/reference/android/app/Activity.html

This basically lets you treat Activity B as an asynchronous remote
procedure call -- you request work be done via startSubActivity(), then
get the results back some time later.

That's the most direct means of communication between two activities,
though, unless I'm forgetting something. Remember that Android might cause
one or the other activity to be frozen and killed off while the other one
is active, due to low memory conditions. Hence, Activity B cannot rely on
Activity A even existing in active memory.

You can always set up a service or content provider as an intermediary
between your two activities, if passing a Bundle back is insufficient. Or,
reconsider why you have two separate activities if they are so tightly
coupled -- perhaps they should be combined into one activity using tabs or
a ViewFlipper or something to toggle between views.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
The Busy Coder's Guide to Android Development -- coming in June 2008!



--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to