启动完成后需要立即启动应用程序

Kar*_*iya 6 android

我需要知道为什么我的应用程序在Android真实手机启动后没有立即运行?我的应用程序在启动几秒后运行.

我的代码是

public class AutoStart extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
         if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
                Intent i = new Intent(context, MyActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
    }

}
Run Code Online (Sandbox Code Playgroud)

我的活动正在运行,但是在几秒钟的启动完成之后.可以减少这几秒吗?

我想立即运行我的应用程序.我不想让用户访问手机.

Ayu*_*ush 12

这可以提高你的优先级,但仍然会有一些延迟.因为android首先加载它的操作系统,所有其他活动开始.

<receiver
    android:name=".AutoStart"
    android:enabled="true"
    android:exported="true"
    <intent-filter android:priority="1000">
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

  • 该值必须是整数,例如"100".数字越大,优先级越高.默认值为0.该值必须大于-1000且小于1000.来自https://developer.android.com/guide/topics/manifest/intent-filter-element.html (3认同)