2012-07-12 80 views
0

我创建的通过点击一个通知的活动发起创建了一个通知,广播reciever,该活动推出,但我不能看见它,我使用下面的代码:活动不显示

private NotificationManager notificationManager; 
    @Override 
public void onReceive(Context context, Intent intent) { 
    if (notificationManager == null) { 
     notificationManager = (NotificationManager) context 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
    } 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
      .setTicker("Its Ticker") 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setContentTitle("Notification Title") 
      .setContentText("Its Content") 
      .setAutoCancel(true) 
      .setContentIntent(PendingIntent.getActivity(context,0,new Intent(context, NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK),0)); 
    notificationManager.notify("interstitial_tag", 0, builder.getNotification()); 

} 

注意:NotificationDialog.java是我的活动,此活动正在运行,因为我调试但未查看。尝试几个小时,但无法找到任何答案,任何建议将不胜感激。

+1

尝试:'.setContentIntent(PendingIntent.getActivity(背景下,0,新的意向(背景下,NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |意向.FLAG_ACTIVITY_CLEAR_TOP),0));' – DroidBender 2012-07-12 09:40:10

+0

谢谢你的工作。发布它作为答案,所以我接受它。 – 2012-07-12 10:23:02

回答

0

使用FLAG_ACTIVITY_CLEAR_TOP,而不是FLAG_ACTIVITY_CLEAR_TASK

private NotificationManager notificationManager; 
    @Override 
public void onReceive(Context context, Intent intent) { 
    if (notificationManager == null) { 
     notificationManager = (NotificationManager) context 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
    } 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
      .setTicker("Its Ticker") 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setContentTitle("Notification Title") 
      .setContentText("Its Content") 
      .setAutoCancel(true) 
      .setContentIntent(PendingIntent.getActivity(context,0,new Intent(context, NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP),0)); 
    notificationManager.notify("interstitial_tag", 0, builder.getNotification()); 

}