when you declare it static..it can't be changed once assigned. Don't use
static. You're trying to use static so that you can access it from the other
class without having to pass it via a method. You could also use a global
staic class instance..

public class MyGlobals {
  static final MyGlbals globals = new MyGlobals();

  int someVarINeedToPassAndChange = 0;

  private MyGlobals(){}

  public static MyGlobals getInstance(){
    return globals;
  }
}

Then, from any class simply call MyGlobals.getInstance() to access the
shared variables you need.

This is but one way to do it. I am sure there are probably better ways.  I
try to pass things via methods when possible.


On Wed, Jan 13, 2010 at 10:16 AM, Sean Hodges
<[email protected]>wrote:

> How about using the SharedPreferences mechanism? It is described in
> the first section of this article:
>
> http://developer.android.com/intl/fr/guide/topics/data/data-storage.html
>
> I used it for the very same purpose. It has the added benefit that the
> value is shared between multiple instances of the app widget, and it
> is persisted even when the widget is removed from the home screen
> (although you could choose to reset it if desired).
>
>
> On Fri, Jan 8, 2010 at 11:53 AM, medpur <[email protected]>
> wrote:
> > Hi,
> >
> > I need to share the value between the activity and app widget ,
> >
> > Is there any way to achieve this other than using the intents.
> >
> > Ex: say x is the variable defined in one class .i need to use the same
> > variable in the other class .how to achieve this.
> >
> > I declared like
> >
> > abc.java
> > Public static int x;
> >
> > The above is working only when it is assigned at the time of
> > declaration.
> >
> > like Publoc static int x=3.
> > i can access this in other class as abc.x
> >
> > But it is not allowing to mofify in the abc.java file .
> >
> > Please let me know ,is there any other solution ,
> >
> >
> > Regards
> > Rajgopal
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Beginners" group.
> >
> > NEW! Try asking and tagging your question on Stack Overflow at
> > http://stackoverflow.com/questions/tagged/android
> >
> > To unsubscribe from this group, send email to
> > [email protected]<android-beginners%[email protected]>
> > For more options, visit this group at
> > http://groups.google.com/group/android-beginners?hl=en
> >
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow at
> http://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> [email protected]<android-beginners%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-beginners?hl=en
>
>
-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

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