Reputation: 1297
I can see many apps that can handle more complex situations like Notifications and it's work verywell.
Requirement:
I'm just trying to set an alarm to fire at specific time
Problem:
It's work only if app exist in recent apps, if I removed it from recent apps no alarm fired!
Questions:
Why it's not working? - What should I do to make it working?
My Code Snipp:
What my alarm firing look like:
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), PENDING_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
assert alarmManager != null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeInMilliseconds, pendingIntent);
} else {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMilliseconds, pendingIntent);
}
What MyBroadcastReceiver look like:
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "MyBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "BroadCast Fired!");
}
Enable for boot:
ComponentName componentName = new ComponentName(this, MyBroadcastReceiver.class);
PackageManager packageManager = getPackageManager();
packageManager.setComponentEnabledSetting(componentName,
componentEnabledState,
PackageManager.DONT_KILL_APP);
Manifest:
<receiver
android:name="MyBroadcastReceiver"
android:enabled="false">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Upvotes: 0
Views: 601
Reputation: 2941
This happens because the manufacturer of your device (Oppo) added a custom setting to kill apps when they are removed from the list of recent apps.
This is NOT standard Android behavior. In normal Android, an app is not killed when removed from the list of recent apps (and that's why it worked correctly on the emulator).
The solution is to locate where this setting resides in your device and change it. In some devices, you may need to pin the app to the list of recent apps too, so it doesn't get removed. But this may change depending on the specific device model.
If you can't find the setting, I recommend to search in Oppo forums or check this page: https://dontkillmyapp.com/
But your code is correct. There's nothing more you can do from the app.
Upvotes: 1