我成功地创建了启动一个服务,它通过转这样表示恢复应用
public int onStartCommand(Intent intent, int flags, int startId){
String notificationText = "working"
myNotification = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("test")
.setContentText(notificationText)
.setTicker("Notification!")
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.build();
//FOLLOWING TECHNIQUE IS DEPRECATED
/* PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
myNotification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); */
myNotification.flags |= Notification.FLAG_NO_CLEAR;
myNotification.flags = Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(1, myNotification);
return START_STICKY;
}
我知道有与此相关的其他问题,但它们都使用的通知活动setLatestEventInfo
它被废弃
这是我从另一个活动调用:
protected void beginBackgroundSer(){
intentService = new Intent(this, Service.class);
intentService.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
this.startService(intentService);
}
所以我想要的是简历每当我点击通过非弃用方法的活动。非常感谢您的帮助。
当我点击它会提醒“很抱歉,但应用程序已中断”的通知执行此操作。任何想法为什么? – 2014-09-10 22:40:51
我看到你接受了一个答案,但你是否得到了你在做错什么?这很重要。你需要知道为什么它说“我们很抱歉,但应用程序已被中断”。 – 2014-09-10 22:54:52