通知不能跳到另一个活动?

时间:2011-08-31 05:14:24

标签: java android

我的代码是

public class AlarmReceiver extends BroadcastReceiver {
public Notification mNotification = null;
public NotificationManager mNotificationManager = null;

@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "time up!", Toast.LENGTH_SHORT).show();
    mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = new Notification(R.drawable.icon, "tip!",
            System.currentTimeMillis());
    mNotification.contentView = new RemoteViews(context.getPackageName(),
            R.layout.notification);
    mNotification.contentView.setTextViewText(R.id.tv_tip, "click to see the description");
    Intent notificationIntent = new Intent(context,NotificationTip.class);
    notificationIntent.putExtra("description", intent.getStringExtra("description")) ;
    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
    mNotification.contentIntent = contentIntent;
    mNotificationManager.notify(0, mNotification);
}

}

当我点击通知中的项目时,我无法进入NotificationTip活动,那么这段代码有什么问题?

1 个答案:

答案 0 :(得分:0)

以下行

 Intent notificationIntent = new Intent(context,NotificationTip.class);

需要

Intent notificationIntent = new Intent("X");

其中X是意图操作名称。这个你必须在你的android清单文件中添加为intent过滤器。