Android 在调用BOOT_COMPLETED后不执行For循环 BootReceiver.kt Manifest.xml
为什么不执行for语句??如何执行for语句??如果你看一下代码,放置Android 在调用BOOT_COMPLETED后不执行For循环 BootReceiver.kt Manifest.xml,android,for-loop,kotlin,broadcastreceiver,bootcompleted,Android,For Loop,Kotlin,Broadcastreceiver,Bootcompleted,为什么不执行for语句??如何执行for语句??如果你看一下代码,放置Thread.sleep(1000)的原因是Toast可能过快。作为参考,删除Thread.sleep(1000)没有执行For语句。没有Thread.sleep(1000)它能工作吗?即使没有Thread.sleep(1000)For语句也不能工作。可能这个方法本身没有被调用。。试试这个谢谢你的建议。操作_BOOT_完成后,启动了startService,但出现了Emulator:qemu:unsupported keybo
Thread.sleep(1000)
的原因是Toast可能过快。作为参考,删除Thread.sleep(1000)
没有执行For语句。没有Thread.sleep(1000)它能工作吗?即使没有Thread.sleep(1000)
For语句也不能工作。可能这个方法本身没有被调用。。试试这个谢谢你的建议。操作_BOOT_完成后,启动了startService,但出现了Emulator:qemu:unsupported keyboard cmd=0x84
错误,服务未运行。
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
for (i in 0 .. 10) {
Toast.makeText(context, "number $i", Toast.LENGTH_SHORT).show()
Thread.sleep(1000)
}
}
}
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application>
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
Toast.makeText(context, "Reboot", Toast.LENGTH_SHORT).show()
}