我需要知道为什么我的应用程序在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);
}
}
}
我的活动正在运行,但是在几秒钟的启动完成之后。可以减少这几秒吗?
我想立即运行我的应用程序。我不想让用户访问手机。
答案 0 :(得分: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>
答案 1 :(得分:1)
Android系统在启动完成后做了很多工作。 因此意图可能会延迟。根据电话功能,意图延迟时间会有所不同。
答案 2 :(得分:0)
我也遇到了这个问题。对于仍在寻找解决方案的任何人:
我想立即运行我的应用程序。我不想允许用户访问电话。
考虑将您的应用变成家庭启动器。在清单中进行更改:
添加到您的活动
android:launchMode="singleTask"
在活动中添加到意图过滤器
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
此后,它将立即与系统一起启动,不会向用户显示其他任何内容。