Java 通知管理器在android中不在倒计时类中工作

Java 通知管理器在android中不在倒计时类中工作,java,android,notifications,Java,Android,Notifications,我正在使用一个倒计时计时器类,在该类的onfinish()状态下,我正在创建一个通知。以下是Onfinish方法的代码: public void onFinish() { notificate(); Log.i("Aler Resume", "Finished"); remtime.setText("0 : 00 : 00"); textCondition.setText(getString(R.st

我正在使用一个倒计时计时器类,在该类的onfinish()状态下,我正在创建一个通知。以下是Onfinish方法的代码:

public void onFinish() {
            notificate();
            Log.i("Aler Resume", "Finished");
            remtime.setText("0 : 00 : 00");
            textCondition.setText(getString(R.string.BuddyAlertExpired));
              }
在notificate()方法中,我写道:

private void notificate() {
        NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  

        Notification note = new Notification(R.drawable.ic_launcher, "New E-mail", System.currentTimeMillis());  

         PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, AlertResume.class), 0); 
         note.setLatestEventInfo(this, "Buddy Alert", getString(R.string.BuddyAlertExpired), intent); 
         note.defaults= Notification.DEFAULT_VIBRATE;
         note.defaults=Notification.DEFAULT_SOUND;
         notifManager.notify(NOTIF_ID, note); 


    }

当我打开我的应用程序时,它工作正常。但是当我从应用程序返回时,onfinish方法正在被调用,我可以正确地看到日志,但是notogation方法不起作用,并且不显示任何通知。有什么错误吗?

当你离开应用程序时,Android可能会认为你运行的倒计时程序是垃圾邮件或额外信息,而不是故意的。完成它的…(好像你忘了关让我关)

因此,最好使用AlarmManager进行上述操作,例如设置PendingEvent-Notification,在启动倒计时时,还可以使用ALARM MANAGER设置具有挂起意图的通知

        nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.drawable.icon, "Test", System.currentTimeMillis());

        Intent intentTL = new Intent(context, MainActivity.class);
        notification.setLatestEventInfo(context, "Test", "Do something!",
                PendingIntent.getActivity(context, 0, intentTL,
                PendingIntent.FLAG_CANCEL_CURRENT));
        notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
        nm.notify(1, notification);

        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
                intent, PendingIntent.FLAG_CANCEL_CURRENT);
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent);