Sna*_*ake 21 android google-cloud-messaging
有没有办法从Context获取应用程序.我注意到activity和service有getApplication()方法,但Context没有.
背景:
我正在使用/扩展GCMBaseIntentService和
protected abstract void onMessage (Context context, Intent intent)
Run Code Online (Sandbox Code Playgroud)
给我一个上下文作为参数.我想获取Application对象,以便我可以将它转发到MyApplication并检索一些变量
谢谢
Ego*_*uba 22
Context#getApplicationContext将返回您的Application实例.
小智 11
val application : Application = context.applicationContext as Application
Run Code Online (Sandbox Code Playgroud)