在我的应用程序中,如果发生特殊事件,我会通过通知来告知用户:
我知道有很多教程可以解释如何处理通知,但我只是不完全理解它们,并且从未能够像我想要的那样实现这些东西。
public void triggerNotification(String msg) {
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent contentIntent = new Intent(this, ABC.class);
Notification notification = new Notification(R.drawable.icon, msg, System.currentTimeMillis());
notification.setLatestEventInfo(this, "ABC", msg, PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent, PendingIntent.FLAG_CANCEL_CURRENT));
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(notificationCounter, notification);
notificationCounter++;
}
如果用户点击通知,则会调用onCreate()方法。但我希望调用我的应用程序中的特定方法,或者如果应用程序不在前台,则将其带回到前台。我知道有很多教程可以解释如何处理通知,但我只是不完全理解它们,并且从未能够像我想要的那样实现这些东西。