具有挂起意图的Android通知

具有挂起意图的Android通知,android,Android,我将根据某些逻辑发送通知 public class DbAdapter_Assignment extends DbAdapter { public DbAdapter_Assignment(Context context) { super(context); } public void deleteUnassignedTask(Assignment[] assignments) { //some logic sendNotification(String a. St

我将根据某些逻辑发送通知

public class DbAdapter_Assignment extends DbAdapter {

public DbAdapter_Assignment(Context context) {
    super(context);
}

 public void deleteUnassignedTask(Assignment[] assignments)
{
    //some logic
    sendNotification(String a. String b);
}

 private void triggerNotification(String s, String id)     
{         
    CharSequence title = "TASK UNASSIGNED";         
    CharSequence message = s;    
    NotificationManager notificationManager;
    notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);         
    Notification notification = new Notification(R.drawable.checkno, s, System.currentTimeMillis());  

    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    // No. 1 solution
    PendingIntent pendingIntent = PendingIntent.getActivity(context, Integer.parseInt(id), null, PendingIntent.FLAG_UPDATE_CURRENT); 
    // -----------

    // No. 2 solution
    Intent notificationIntent = new Intent(context, MyTask.class);
    notificationIntent.putExtra("EmpID", Functions.getLoginEmpID(context));
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP );
    PendingIntent pendingIntent = PendingIntent.getActivity(context,
            Integer.parseInt(id), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    // ----------------

    notification.setLatestEventInfo(context, title, message, pendingIntent);  
    notificationManager.notify(Integer.parseInt(id), notification);    
} 
}


第一个解决方案正在发挥作用。我想添加的是,如果单击该通知,则转到MyTask类。所以我尝试了2号解决方案,但它对我不起作用。如果使用2号解决方案,它不会显示任何通知。我缺少什么?ir是因为该类不是活动或服务吗?

您的
通知对我来说很合适。
我没有尝试在扩展
活动的类之外创建
通知
,但是我假设如果您可以访问
通知管理器
,那么您应该可以这样做

您所指向的类是否将
挂起内容
扩展为
活动

您的
pendingent
正在使用的
活动中是否存在问题


这是AndroidManifest.xml中的
活动吗?

我想我们需要查看MyTask来回答这个问题。