protected void displayNotification(String response) {
Intent intent = new Intent(context, testActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification = new Notification(R.drawable.icon, "Upload Started", System.currentTimeMillis());
notification.setLatestEventInfo(context, "Upload", response, pendingIntent);
nManager.notify((int)System.currentTimeMillis(), notification);
}
Run Code Online (Sandbox Code Playgroud)
该函数将被多次调用.我希望每个人notification在点击时启动testActivity.不幸的是,只有第一个通知启动testActivity.单击其余部分会导致通知窗口最小化.
额外信息:函数displayNotification()在一个叫做的类中UploadManager. 从实例化Context传递进来.函数在函数中多次调用,也在UploadManager中运行.UploadManageractivitydisplayNotification()AsyncTask
编辑1:我忘了提到我正在将String响应传递Intent intent给extra.
protected void displayNotification(String response) {
Intent intent = new Intent(context, testActivity.class);
intent.putExtra("response", response);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)
这有很大的不同,因为我需要额外的"响应"来反映创建通知时的字符串响应.相反,使用PendingIntent.FLAG_UPDATE_CURRENT,额外的"响应"反映了最后一次调用时String响应displayNotification().
我知道为什么这是通过阅读文档 …