如果应用程序被杀死,警报管理器不会触发

Alarm manager is not triggering if app is killed

我正在尝试创建一个日程安排应用程序。我正在使用警报管理器。当应用程序处于活动状态时它工作正常。如果我从最近的应用程序中删除了该应用程序,则不会触发警报。请让我知道如何解决我的问题。在此附上我的代码。

AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(SettingsPage.this, AlarmManagerForSettings.class);
i.putExtra("requestCode", "100");
i.putExtra("AlarmTag",id);
PendingIntent pi = PendingIntent.getBroadcast(SettingsPage.this, (int)id, i, 0);
am.cancel(pi); // cancel any existing alarms RTC_WAKEUP
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, time, AlarmManager.INTERVAL_DAY, pi);
ComponentName receiver = new ComponentName(SettingsPage.this, AlarmManagerForSettings.class);
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                            PackageManager.DONT_KILL_APP);

广播接收器:-

public class AlarmManagerForSettings extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        String requestCode = "";
        String alarmTag = "";
        if (bundle != null) {
            requestCode = bundle.get("requestCode").toString();
            alarmTag = bundle.get("AlarmTag").toString();
        }
//Rest of code I wrote here
   }
}

清单:-

<receiver
  android:name=".AlarmManagerForSettings"
  android:enabled="true"
  android:exported="true">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"></action>
  </intent-filter>
 </receiver>

一些移动广播接收器不是 运行..如果广播不是 运行 请按照以下步骤操作: 在小米设备中,您只需将您的应用程序添加到自动启动列表,为此,请按照以下简单步骤操作:

1.Open Security app on your phone.

2.Tap on Permissions, it'll show you two options: Autostart and Permissions

3.Tap on Autostart, it'll show you list of apps with on or off toggle buttons.

4.Turn on toggle of your app, you're done!

在粘性服务器 class 中编写您的警报管理器代码,然后根据您的功能启动此服务。杀死应用程序后检查正在更新。