Not only is it not an Activity, but an Application -- it may not even
be YOUR Application in some cases.

You should never use getApplicationContext(). Just use the current
activity itself, or if you need YOUR application, call
getApplication().

Accessing other activities is a mistake. It requires you to keep a
reference to them to access them - and that prevents their storage
from being garbage collected. Perhaps you need to refactor some of
your code into a separate common class, or to place your common code
on your Application class instead?

Either way, you do need to be careful. Neither the Application, nor
the common object, should hang onto things relating to activities. No
view instances, and no data that is only needed within a specific
activity.

On Jun 19, 11:54 pm, Gaurav Vaish <[email protected]> wrote:
> Application Context is not an activity but just "Context" (It's actually,
> Application)
>
> -Gaurav
>
>
>
>
>
> On Sun, Jun 20, 2010 at 12:01 PM, mike <[email protected]> wrote:
> > hi guys,
>
> > i have Activity A and Activity B
>
> > i want to access a method in Activity A from Activity B
>
> > this is my method
> > Activity A extends activity{
>
> >   public void save(){
>
> >   }
> > }
>
> > this is what i have done from activity B
>
> > Activity B extends activity{
>
> >   public void access{
>
> >                AcitvityA noti = (AcitvityA) getApplicationContext();
> >                noti.save();
>
> >   }
>
> > }
>
> > and i'm getting a runtime exception saying
>
> > java.lang.ClassCastException: android.app.Application
>
> > how can i access this method from another activity??
>
> > regards,
> > Mike
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<android-developers%2Bunsubs 
> > [email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
>
> --
> Cheers,
> Gaurav Vaishhttp://mastergaurav.comhttp://twitter.com/mastergaurav
> ----------------------------

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to