android – How to get Application from Context-ThrowExceptions

Exception or error:

Is there a way I can get application from Context. I noticed that activity and service has getApplication() method but Context does not.

Background:

I am using/extending the GCMBaseIntentService and the

protected abstract void  onMessage (Context context, Intent intent) 

gives me a context as a parameter. I would like to get the Application object so I can downcast it to MyApplication and retrieve some variables

Thanks

How to solve:

Context#getApplicationContext will return your Application instance.

Leave a Reply

Your email address will not be published. Required fields are marked *