我有一个警报管理器,它正在调用一个名为ScheduleAlert的活动类。
public class ScheduleAlert extends ActivityGroup {
private String notificationAlart, editEventid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...........
..........
// ************* Notification ************//
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp", nextAlarmTime);
Context context = getApplicationContext();
CharSequence contentTitle = "Myapp";
CharSequence contentText = notificationAlart;
Intent notifyIntent = new Intent(context, MyApp.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ScheduleAlert.this, 0, notifyIntent,android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,pendingIntent);
notifyDetails.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_AUTO_CANCEL;
notifyDetails.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
mNotificationManager.notify((int) editEventid, notifyDetails);
// ************* Notification ************//
this.finish();
}
public void onDestroy(){
super.onDestroy();
}
}
我希望点击通知按钮时,MyApp活动的缩进应该触发。在通知时我想要声音和振动。但是现在我正在获得声音和振动,而MyApp活动也被解雇了,我实际上并不想要。我的代码有什么问题?
答案 0 :(得分:1)
这段代码有很多奇怪的东西:
ActivityGroup
getApplicationContext()
,例如此ActivityGroup
(无论出于何种原因)而不是Service
,因此操作系统和用户误导FLAG_FOREGROUND_SERVICE
FLAG_FOREGROUND_SERVICE
和FLAG_AUTO_CANCEL
组合起来没什么意义但是,我不希望这会导致MyApp
自动启动。事实上,在AFAIK中,Notification
没有用户点击它就会自动调用PendingIntent
的情况。我怀疑你真正的问题出在其他地方。