【发布时间】:2013-02-12 16:40:34
【问题描述】:
我为 android 编写应用程序,它将与 GCM 通信。我可以收到消息,但我想在屏幕上显示它并收到错误消息。
有我的代码,我在 Activity act = (Activity) context 行有问题;
我收到错误“此类文件的 JAR 属于容器‘Android 依赖项’,它不允许修改其条目上的源附件”
@Override
protected void onMessage(Context context, Intent indent) {
String message = indent.getExtras().getString("message").toString();
Log.i(TAG, "new message= " + message);
Activity act = (Activity) context;
if(act != null)
{
TextView pushNotification = (TextView) act.findViewById(R.id.txtPushNotify);
pushNotification.setText(message);
}
}
我做错了什么??这个方法在类中
public class GCMIntentService extends GCMBaseIntentService {...}
这是我的 LogCat
致命异常:IntentService[GCMIntentService-19193409722-1] java.lang.ClassCastException:android.app.Application
在 com.sagar.gcma.GCMIntentService.onMessage(GCMIntentService.java:41)
在 com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
在 android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
在 android.os.Handler.dispatchMessage(Handler.java:99)
在 android.os.Looper.loop(Looper.java:123)
在 android.os.HandlerThread.run(HandlerThread.java:60)
【问题讨论】:
-
您可能想发布整个 logcat 错误,为人们提供更好的信息
-
您正在尝试将 Service 的上下文投射到 Activity 中,我认为这是不可能的。
-
如何在屏幕上显示 GCMIntentService 类的内容?
-
你为什么写
Activity act = (Activity) context;代码?相反,您应该创建一个新的 Intent 并启动该活动。
标签: java android google-cloud-messaging