Ah.. Thank you. That clears up a lot !!!

 

I was thinking that a static variable created in an activity would be
"global" only to that activity, and any spawned processes of that activity.
But now. knowing it is at the application level open up many possibilities.
When I was designing my current process I remember thinking that it would be
very handy to have an application level global variable, but never got
around to asking the question. And because I am coding on a Windows machine
with Eclipse, I'd rather go to the dentist than try to trace through the
Android source code :-)

 

Actually, I was thinking of moving some of my threads to a service just for
efficiency reasons (to save on multiple requests for the same information),
but now.. I think if I implement this the way you laid it out, the service
seems to be overkill. My threads only download small thumbnail bitmaps, or
send fairly fast REST queries to my server, so I don't think I'd need the
service at all. I think you just saved me several days coding ;)

 

Hmm.What happens in this sequence :   Activity A sets the static variable,
and then creates the thread to get some information. The user then clicks on
the first piece of information returned, and goes to Activity B. But
activity B then takes the user to another instance of activity A. Then the
two instances of activity A would be sharing the static variable that points
to the second instance of activity A ... correct?

 

I don't think this is a huge problem because my activity A can only be
called in two ways, and I can declare two static variables in activity A and
then assign the one that corresponds to how activity A was called, and use
it to pass to the threads, so that each instance of Activity A would have
their own static variable to use with the threads that they create.. Does
that sound correct?

 

 

 

Sincerely,

 

Brad Gies

 

 

-----------------------------------------------------------------

Brad Gies

27415 Greenfield Rd, # 2,

Southfield, MI, USA

48076

www.bgies.com  www.truckerphone.com 

www.EDI-Easy.com  www.pricebunny.com

-----------------------------------------------------------------

 

Moderation in everything, including abstinence

  _____  

From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of Dianne Hackborn
Sent: Sunday, January 25, 2009 8:23 PM
To: android-developers@googlegroups.com
Subject: [android-developers] Re: Activity Issue on G1 phone

 

I meant that the static variable would -hold- the current activity.

Everything in your .apk runs in one process.  When you declare a static
variable, that is creating a global to all code in that process.  You can
make a static variable pointing to an Activity:

    static Activity mCurActivity = null;

In your activity's onCreate() set it to 'this'.  In onDestroy() set it to
null.

Now someone else -- a thread or whatever -- can come in, and retrieve the
value of mCurActivity to find out the current activity that has been set.

On Sun, Jan 25, 2009 at 4:47 PM, Brad Gies <rbg...@gmail.com> wrote:


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to