Short answer:
Don't use static variables :-)

Somewhat longer answer:
If sub-activities need to access some data held by my main activity, i
usually do create one static variable:

public MyActivity extends Activity {
  >> public static final MyActivity ACTIVE_INSTANCE; <<

  protected void onCreate(Bundle b) {
    super.onCreate(b);
    ACTIVE_INSTANCE = this;
    ...
    ...
  }

  protected void onDestroy() {
    ...
    ...
    ACTIVE_INSTANCE = null;
    super.onDestroy();
  }
  ...
  ...
}

Then sub-activities (and other classes) can access MyActivity's
instance variables/methods through MyActivity.ACTIVE_INSTANCE.

Still, though, try to avoid statics (unless they're final) as much as
possible. Use parameters/Intents to pass data.

On Apr 1, 1:37 am, wacamoe <waca...@gmail.com> wrote:
> Hello all,
>   I have noticed in my application(s) that after a call to
> Activity.finish() that the static variables that I declared in my
> classes still hold the values that they were changed to during the
> activity's life cycle. Upon the re-launch of the activity, the program
> does not re-instantiate the variables as declared or set them to the
> default java behavior. Is there something that I can do to cause this
> to happen, other than re-setting every static variable in my
> application?
--~--~---------~--~----~------------~-------~--~----~
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