我的问题是,如果我点击通知,它会关闭,但它不会打开活动 Vertretungsplan。问题是什么?
这是我的代码:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
int auswertungsergebnis = 0;
boolean weekday = checkDay();
if (weekday == true) {
auswertungsergebnis = auswerten();
}
String ausgabe = ausfaller.toString().replace("[", "").replace("]", "");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION);
registerReceiver(notifyServiceReceiver, intentFilter);
// Send Notification
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_stat_gymi,
"Notification!", System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Neue Vertretungsstunden!";
String notificationText = ausgabe + " fällt heute aus";
Intent myIntent = new Intent(context, Vertretungsplan.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
getBaseContext(), 0, myIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context, notificationTitle,
notificationText, pendingIntent);
if (auswertungsergebnis == 1) {
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
}
return super.onStartCommand(intent, flags, startId);
}
提前谢谢你:)
答案 0 :(得分:1)
您正在将Intent.FLAG_ACTIVITY_NEW_TASK
传递给PendingIntent.getActivity
- 该标志需要添加到Intent
本身:
Intent myIntent = new Intent(context, Vertretungsplan.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(
getBaseContext(), 0, myIntent, 0);