【发布时间】:2014-03-11 11:02:20
【问题描述】:
我正在BrodCastReceiver 上做一个程序。因此,在我的程序中,当收到任何事件时,它会显示通知,但在单击相同的通知后,它不会启动指定的活动。
这是我的代码
public void onReceive(Context context, Intent i) {
// TODO Auto-generated method stub
Intent intent=new Intent(context, MainActivity.class);
Toast.makeText(context, "Priority 2", Toast.LENGTH_SHORT).show();
mBuilder=new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.build();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder);
PendingIntent.getBroadcast(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
mNotificationManager.notify(1, mBuilder);
}
【问题讨论】:
-
您是否将待处理的 Intent 设置为
builder?
标签: android android-intent notifications