使用 AlarmManager
类,我可以在 200 毫秒后安排通知(用于测试)代码:
Intent alarmIntent = new Intent(this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
int interval =200;
manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),interval, pendingIntent);
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
SetUpNotification.createNotification();
}}
但是当我清除 RAM 时,这些通知会停止,即使我关闭 Activity ,我也可以收到这些通知,但在清除 ram 后就不会收到这些通知,我不知道我犯了什么错误,请帮忙
最佳答案
MIUI解决方案 7.0 => 安全 => 自动启动 => 选择您想要在后台运行的应用程序 => 重新启动 重新启动后,您的设备应该能够像其他 Android 设备一样在后台运行您的应用程序服务。
关于java - 清除 RAM 停止显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39433586/