gpt4 book ai didi

android - BOOT_COMPLETED 的 BroadcastReceiver 太慢

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:42:31 33 4
gpt4 key购买 nike

下面是我的 list 文件。

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mccheekati.test_trail">
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<receiver
android:name="com.example.mccheekati.test_trail.yourActivityRunOnStartup"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

广播接收者如下:

    public class yourActivityRunOnStartup extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}

没有错误。该应用程序在重新启动手机时打开。但是重启后需要一分钟的时间来启动应用程序。有什么重启后立即启动应用程序吗?

最佳答案

Is there any what to start the application immediately after reboot?

没有。

有很多应用程序希望在启动时获得控制权。轮到您的速度取决于许多变量,例如已安装的应用程序数量、设备的 CPU 速度、设备上的系统 RAM 容量等。

此外,在启动时从 BroadcastReceiver 启动一个 Activity 是相当邪恶的。如果您想成为用户在重启后看到的第一件事,请编写一个主屏幕实现。

关于android - BOOT_COMPLETED 的 BroadcastReceiver 太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43988566/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com