licorna wrote:
> Thanks for the quick reply Mark, but what I'm trying to do is not to
> access data (as strings or floats) or passing data between activities,
> but accessing the instantiated caller class or some of its methods or
> members.

I understand that. I don't think it's possible, and even if it is, you 
don't want to do that.

 > For example:
> 
> class FirstClass {
>    ...
>    Object myObject = null;
>    ...
>    intent = new Intent(..., SecondClass.class);
>    startSubActivity(intent, ...); // SecondClass
> }
> 
> class SecondClass extends Activity{
>    @Override
>    public onCreate(Bundle b){
>       // Access FirstClass().myObject o FirstClass
>    }
> }
> 
> This way SecondClass is asynchronous with FirstClass so they should be
> able to communicate.

You are assuming the FirstClass object exists when SecondClass needs it. 
It might, but it might not.

It is possible that, while SecondClass is active, Android will have 
called onPause(), onFreeze(), and shut down the FirstClass object to 
garbage-collect it, because it's out of RAM. Ordinarily, this would not 
be a problem -- when the FirstClass activity is set to be redisplayed, 
it will simply be re-created (i.e., thawed out).

For this to work, though, SecondClass cannot have a way to hold onto the 
FirstClass object, otherwise the garbage collection won't work, and you 
wind up with a very sad Android. :-(

 > Is any way of doing this or I'll have to redesign?

Why are they separate activities, if they are so closely coupled?

If there is a scenario where something else launches SecondClass (e.g., 
some other activity in your application, or a third-party activity), 
then SecondClass really really really really should not be assuming the 
FirstClass object exists in RAM, since it may be that it was never 
started in the first place.

If there is no scenario where something else launches SecondClass -- 
it's always spawned by FirstClass -- and they are so closely tied that 
one cannot exist without the other, maybe they should be just one 
activity, using a ViewFlipper or TabActivity 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