Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 应用程序未运行时,广播接收器不会启动活动_Kotlin_Android Intent_Android Activity_Broadcastreceiver - Fatal编程技术网

Kotlin 应用程序未运行时,广播接收器不会启动活动

Kotlin 应用程序未运行时,广播接收器不会启动活动,kotlin,android-intent,android-activity,broadcastreceiver,Kotlin,Android Intent,Android Activity,Broadcastreceiver,我试图通过广播接收器打开活动 这是舱单: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.andreasgift.myclock"> <uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> <application a

我试图通过广播接收器打开活动

这是舱单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.andreasgift.myclock">

    <uses-permission android:name="com.android.alarm.permission.SET_ALARM" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@drawable/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".Alarm.AlarmNotifActivity" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SET_ALARM" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <receiver android:name=".Alarm.AlarmReceiver" />
    </application>

</manifest>
这是广播接收器类:

class AlarmReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context, intent: Intent) {
        val openNext = Intent(context, AlarmNotifActivity::class.java)
        openNext.putExtra(Constants().ALARM_LABEL_KEY, intent.getStringExtra(Constants().ALARM_LABEL_KEY))
        openNext.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(openNext)
        Log.d("ALARM","Broadcast receiver working")
    }
}
当应用程序打开时,该功能工作正常。但是,当应用程序关闭时,它似乎不会执行startActivity(Intent)。但它确实在广播接收器中执行了最后一个log.d

我试图用context.applicationContext替换context,但它没有改变任何东西。 我曾尝试将活动类替换为另一个活动,但也没有成功。 我试着将开放式活动改为展示祝酒词。吐司被展示,工作非常好

以下是广播接收器执行onReceive后的logcat

2019-11-05 16:42:29.962 1992-3189/system_process I/ActivityTaskManager: START u0 {flg=0x10000000 cmp=com.andreasgift.myclock/.Alarm.AlarmNotifActivity (has extras)} from uid 10133
2019-11-05 16:42:29.962 1992-3189/system_process W/ActivityTaskManager: Background activity start [callingPackage: com.andreasgift.myclock; callingUid: 10133; isCallingUidForeground: false; isCallingUidPersistentSystemProcess: false; realCallingUid: 10133; isRealCallingUidForeground: false; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: null; isBgStartWhitelisted: false; intent: Intent { flg=0x10000000 cmp=com.andreasgift.myclock/.Alarm.AlarmNotifActivity (has extras) }; callerApp: ProcessRecord{c678bfd 7783:com.andreasgift.myclock/u0a133}]
2019-11-05 16:42:29.963 1992-2036/system_process I/libprocessgroup: Successfully killed process cgroup uid 10095 pid 6926 in 79ms
2019-11-05 16:42:29.964 7783-7783/com.andreasgift.myclock D/ALARM: Broadcast receiver working
有人知道这里出了什么问题吗

2019-11-05 16:42:29.962 1992-3189/system_process I/ActivityTaskManager: START u0 {flg=0x10000000 cmp=com.andreasgift.myclock/.Alarm.AlarmNotifActivity (has extras)} from uid 10133
2019-11-05 16:42:29.962 1992-3189/system_process W/ActivityTaskManager: Background activity start [callingPackage: com.andreasgift.myclock; callingUid: 10133; isCallingUidForeground: false; isCallingUidPersistentSystemProcess: false; realCallingUid: 10133; isRealCallingUidForeground: false; isRealCallingUidPersistentSystemProcess: false; originatingPendingIntent: null; isBgStartWhitelisted: false; intent: Intent { flg=0x10000000 cmp=com.andreasgift.myclock/.Alarm.AlarmNotifActivity (has extras) }; callerApp: ProcessRecord{c678bfd 7783:com.andreasgift.myclock/u0a133}]
2019-11-05 16:42:29.963 1992-2036/system_process I/libprocessgroup: Successfully killed process cgroup uid 10095 pid 6926 in 79ms
2019-11-05 16:42:29.964 7783-7783/com.andreasgift.myclock D/ALARM: Broadcast receiver working