My BroadcastReceiver is set up to receive ON_BOOT_COMPLETE
In my app, I have an if statement:
BroadcastReceiver.kt:
class BroadcastReceiverTest : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent)
if (intent.action = Intent.action.BOOT_COMPLETED) {
Toast.makeText(context, "BOOT_COMPLETE FLAG", Toast.LENGTH_SHORT).show()
}
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Example">
<receiver
android:name=".receiver.BroadcastReceiverTest"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.Example">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I force-stop my app, then relaunch it, the BOOT COMPLETE toast shows up.
My BroadcastReceiver picks up a BOOT_COMPLETE broadcast, even though my phone hasn't rebooted, but only after I force stop the app.