如何在应用程序关闭时收到通知?

How to receive notification when the application is closed?

我正在制作一个 android 应用程序,我想在应用程序关闭时收到通知,我该怎么做?我也读过其他人问的帖子,但我不明白如何让它发挥作用,你能试着更好地解释一下吗?

我还尝试制作一个倒数计时器并让应用程序在计时器到达 0 时执行某些操作,但它不起作用,因为很明显,当我关闭应用程序时,我也关闭了计时器。

使用此代码进行应用内通知

NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher) // notification icon
            .setContentTitle("Notification!") // title for notification
            .setContentText("Hello word") // message for notification
            .setAutoCancel(true); // clear notification after click
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());