Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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
Android 在调用BOOT_COMPLETED后不执行For循环 BootReceiver.kt Manifest.xml_Android_For Loop_Kotlin_Broadcastreceiver_Bootcompleted - Fatal编程技术网

Android 在调用BOOT_COMPLETED后不执行For循环 BootReceiver.kt Manifest.xml

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

为什么不执行for语句??如何执行for语句??如果你看一下代码,放置
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()
}