写了个程序。这个程序需要开机后自动启动。按照网上的也结合书上的写好程序后。出现了一下问题:1.关掉程序,用“重启”按钮重启手机。手机启动后,程序可以自动启动。
2.关掉程序,先把手机关机。然后再开机。程序就不能自动启动了。
3.开着程序的情况下,不管是“重启”还是关机再开机,程序都可以自动启动。就是那个2,不知道为什么不能自动启动呢?关于自动启动的部分,大概代码如下。MyReceriver.javapublic class MyReceriver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intent1 = new Intent(context,MyService.class);
context.startService(intent1);
}}
AndroidManifest.xml<receiver android:name=".MyReceriver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.home"/>
</intent-filter>
</receiver>
2.关掉程序,先把手机关机。然后再开机。程序就不能自动启动了。
3.开着程序的情况下,不管是“重启”还是关机再开机,程序都可以自动启动。就是那个2,不知道为什么不能自动启动呢?关于自动启动的部分,大概代码如下。MyReceriver.javapublic class MyReceriver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent intent1 = new Intent(context,MyService.class);
context.startService(intent1);
}}
AndroidManifest.xml<receiver android:name=".MyReceriver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.home"/>
</intent-filter>
</receiver>
解决方案 »
- android编译时没错误,但是不能执行,求救!
- 求助各位大神,蓝牙串口如何完整接收inputstream中的数据
- android 中static的用法
- 有没有人推荐一个Android开发群。
- 接口本身能像类那样实例化吗?
- JDK环境变量设置问题
- android EditText
- 求助:新手寻好的Android入门教程以及学习规划(有java基础)
- 用json获取的PHP网页在WebView中显示,HTC手机全部能显示三星手机不能显示图片,请问这是为什么啊?
- 求MediaCodec.createInputSurface视频编码dequeueOutputBuffer返回-1问题
- 请教:PopupWindow的一个问题
- 自动发彩信
帮帮忙吧
mContext = context;
if(intent.getAction().equals( Intent.ACTION_BOOT_COMPLETED )){
Log.d("11", "boot is start------------------------>start modem.service");
Intent i=new Intent(context, modem.class);
context.startService(i);
}