我在android中执行notification
时出错。实际上我已经添加通知,当我从服务器获取新消息时。我已在此处添加了代码,但问题是当我点击通知时重定向完美,但活动结束。
protected void NotificationManager(String Msg) {
if (Msg.equals("0"))
Msg = "New Image Received";
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.icon,"Notification!", System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "NEWMESSGE";
String notificationText = Msg;
Intent myIntent = new Intent(Intent.CATEGORY_HOME, Uri.parse(myBlog), context, com.example.home.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
PendingIntent pendingIntent = PendingIntent.getActivity(home.this, 0, myIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context, notificationTitle,notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);}
}
在活动中我添加了
Storage.setNotificationFlag(Home.this, "false");
其中Storage
是我已分配所有shared preferences
任何人都可以帮助我。@谢谢