奥利奥:未运行应用程序时未触发警报 [英] Oreo: Alarm is not fired when Application is not running

查看:99
本文介绍了奥利奥:未运行应用程序时未触发警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相对简单的设置,该设置应在一天中的特定时间触发警报并向用户显示通知.这是相对代码,

I have relatively simple setup that should trigger an alarm at certain time of the day and show a notification to user. here is relative code,

设置闹钟

 long inTime = /*expirationTime*/ Calendar.getInstance().getTimeInMillis() + 10000;
 Intent startIntent = new Intent("parking.event");
 startIntent.setClass(getBaseContext(), ParkingExpirationWarmingBroadcast.class);
 PendingIntent startPendingIntent = PendingIntent.getBroadcast(this, 99, startIntent, 0);


 alarmMgr.setExact(AlarmManager.RTC_WAKEUP,
                inTime,
                startPendingIntent);

广播接收器已注册

    <receiver
      android:name=".modules.parking.ParkingExpirationWarmingBroadcast"
      android:enabled="true">
        <intent-filter>
            <action android:name="parking.event" />
        </intent-filter>
    </receiver>

广播接收器

class ParkingExpirationWarmingBroadcast : BroadcastReceiver() {

    @SuppressLint("NewApi")
    override fun onReceive(context: Context, intent: Intent) {
    }
}

仅当应用程序在后台运行时,接收器才会被触发.从多任务中轻扫应用程序后,通知将被清除,并且不会触发新的警报.我在Android 7.0上检查了此设置,无论是否运行应用程序,都会触发BroadcastReceiver.

The receiver is only getting triggered if app is in background. as soon as i swipe the app from multitasking, the notification is cleared and no new Alarms are triggered. I checked this setup on Android 7.0 and BroadcastReceiver is triggered regardless of app running or not.

我知道有关Android Oreo中隐式广播的限制,但是我不认为我上面提到的意图被认为是隐式的.

I am aware regarding restrictions over implicit broadcasts in Android Oreo but i don't believe the intent that i have mentioned above is considered implicit.

谁能指出我做错了什么?

Can anyone point out what i am doing wrong?

推荐答案

强制关闭应用会破坏其组件.这就是强制停止的作用.这不是错误,它是一个很大的功能.遵循以下主题,android框架工程师已对其进行了讨论. https://groups.google.com/forum/? fromgroups =#!topic/android-developers/anUoem0qrxU

Force closing an app destroys its components . This is what force stop does. It's not a bug, it is very much a feature. Follow the following thread , it has been discussed by android framework engineers . https://groups.google.com/forum/?fromgroups=#!topic/android-developers/anUoem0qrxU

这篇关于奥利奥:未运行应用程序时未触发警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆