我在 android 中有一个应用程序,我想在某些情况下将活动带到前台。我为此使用 NotificationManager。这是我的代码。问题是,活动第一次成功地被带到了前面,但后来却没有。此外,此代码是从服务运行的。
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(contentIntent)
.setContentTitle("Bring me front!")
.setContentText("Bring me!!! BRING!!!")
.setFullScreenIntent(contentIntent, true);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());