我想知道为什么我的应用程序在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);
}
}
}我的活动正在运行,但在启动几秒钟后就完成了。有没有可能缩短这几秒钟?
我想立即运行我的应用程序。我不想允许用户访问电话。
发布于 2013-06-05 14:25:07
这可以增加你的优先级,但仍然会有一些延迟。因为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>发布于 2020-09-07 03:11:10
我也遇到过这个问题。对于任何仍在寻找解决方案的人:
我想立即运行我的应用程序。我不想允许用户访问电话。
考虑把你的应用变成家庭启动器。在清单中进行更改:
添加到您的活动
android:launchMode="singleTask"添加到活动中的意图过滤器
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />之后,它将与系统立即启动,不会向用户显示任何其他内容。
发布于 2013-06-05 14:15:19
Android系统在启动完成时做了很多工作。因此,意图可能会被推迟。根据电话功能的不同,意图延迟时间会有所不同。
https://stackoverflow.com/questions/16932701
复制相似问题