记录下该问题,自启动广播代码如下:
class BootBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == "android.intent.action.BOOT_COMPLETED") {
val startupIntent = Intent(context, SplashActivity::class.java)
context.startActivity(startupIntent)
}
}
}
然后报错:
java.lang.RuntimeException: Unable to start receiver ai.xmov.dualscreencanteen.service.BootBroadcastReceiver: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
06-18 10:39:33.431 E/AndroidRuntime( 1521): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2636)
06-18 10:39:33.431 E/AndroidRuntime( 1521): at android.app.ActivityThread.access$1700(ActivityThread.java:151)
06-18 1