我想通知打开创建它的活动。我正在使用ActionBarSherlock,我的代码如下所示:
public class CurrentActivity extends SherlockFragmentActivity {
private void remindMeAlert() {
Intent intent = new Intent(this, CurrentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new NotificationCompat.Builder(this)
.setContentTitle("title")
.setContentText("text")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).build();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}
}
按下通知时,这不会执行任何操作。但是,如果我打开任何其他活动,如:
Intent intent = new Intent(this, DifferentActivity.class);
工作正常。