1

我在 GCM 中为一个 android 应用程序创建了一些通知,我可以很好地创建通知,但是当我尝试从下拉栏中打开它们时,我的应用程序没有打开。签入 LogCat 我可以看到如下回溯:

08-21 22:31:31.250: ERROR/ActivityManager(275): startLaunchActivity get appname failed
        java.lang.NullPointerException
        at com.android.server.am.ActivityStack.startLaunchActivity(ActivityStack.java:4654)
        at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3196)
        at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:2628)
        at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:231)
        at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:182)
        at android.content.IIntentSender$Stub.onTransact(IIntentSender.java:64)
        at android.os.Binder.execTransact(Binder.java:338)
        at dalvik.system.NativeStart.run(Native Method)
08-21 22:31:31.250: INFO/ActivityManager(275): START intent from pid -1

有什么想法是什么原因造成的,我该如何解决?如果需要,我可以提供代码。

谢谢!

通知创建代码:

@Override
protected void onMessage(Context context, Intent intent) {
    String msg = intent.getStringExtra(Constants.FIELD_MESSAGE);

    Log.e("We got a message from the server",msg);

    NotificationManager manager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = prepareNotification(context, msg);
    manager.notify(R.id.notification_id, notification);
    Log.e("Sent notification event","");
}
private Notification prepareNotification(Context context, String msg) {
    long when = System.currentTimeMillis();
    Notification notification = new Notification(R.drawable.ic_stat_cloud, msg,
            when);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    Intent intent = new Intent(context, MessageActivity.class);
    // Set a unique data uri for each notification to make sure the activity
    // gets updated
    intent.setData(Uri.parse(msg));
    intent.putExtra(Constants.FIELD_MESSAGE, msg);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            0);
    String title = context.getString(R.string.app_name);
    notification.setLatestEventInfo(context, title, msg, pendingIntent);

    return notification;
}

通知处理代码:

public class MessageActivity extends Activity {
    private TextView mMessageView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("opening message notification","");
        setContentView(R.layout.activity_message);
        Log.e("displaying message","");
        mMessageView = (TextView) findViewById(R.id.message);
        Log.e("put message","");
    }

    @Override
    public void onResume() {
        super.onResume();
        String msg = getIntent().getStringExtra(Constants.FIELD_MESSAGE);
        mMessageView.setText(msg);
    }
}
4

1 回答 1

3

从错误来看,我怀疑您忘记将 MessageActivity 添加到 Android 清单文件

于 2012-08-21T22:13:35.850 回答