我在我的应用程序中发生了一个警报,它会启动一个通知,然后在按下时启动一个活动.问题是,当我创建多个警报时,从通知启动的活动会获得与第一个相同的额外内容.我认为这个问题要么是我在未决意图中的意图,要么是在未决意图本身.我想我可能需要在其中一个上放一面旗帜,但我不知道哪一个.
Intent showIntent =new Intent(context, notificationreceiver.class);
showIntent.putExtra("details", alarmname);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
showIntent, 0);
notification.setLatestEventInfo(context, "The event is imminent",
alarmname, contentIntent);
Run Code Online (Sandbox Code Playgroud)
和通知的接收者
Bundle b = getIntent().getExtras();
String eventname = b.getString("details");
details.setText(eventname);
Run Code Online (Sandbox Code Playgroud)
每次下次通知发生时,"详细信息"额外都是相同的,而不是具有不同的值.直到我设置意图,我确信正确的值转到"详细信息",因此每次按任何通知时都会获得第一个意图的问题.如何才能启动正确的意图呢?希望我尽可能清楚,谢谢!
我的应用状态栏中有通知:
Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
Intent notificationIntent = new Intent(this.parent, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.parent, 0, notificationIntent, 0);
...
notification.flags = Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)
这个问题是当你从应用程序按下主页按钮(将其推到后台),然后按下从状态栏访问的列表中的通知,它会启动活动的新副本.我想要做的就是恢复应用程序(比如当你长按主页按钮并按下应用程序的图标时).有没有办法创建一个Intent来做到这一点?
我正在尝试将我的通知编程为RESUME我的应用程序,而不是简单地启动我的应用程序的新实例...我基本上是在寻找它做同样的事情,因为长按主页按钮并恢复应用程序从那里.
这是我目前正在做的事情:
void notifyme(String string){
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
int icon = R.drawable.notification_icon; // icon from resources
CharSequence tickerText = string + " Program Running..."; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = *********; // expanded message title
CharSequence contentText = string + " Program Running...";//expanded msg text
Intent notificationIntent = new Intent(this, Main.class);
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, notificationIntent, 0);
// the …Run Code Online (Sandbox Code Playgroud)