解决方案 »

  1.   

    我现在仅仅是让在BroadcastReceiver里面让他用log输出一个标志,可是开机后没法输出啊?
      

  2.   

    没真机吗?
    记得模拟器好些可以模拟开关机的,我2.3的模拟器长按挂机键,在最后的Power off dialog就停那里关不了也开不了。
      

  3.   

    这里,打印调试可以输出文件,logcat打印,因为广播的参数有context,你可以startActivity,不过需要加入NewTask这个标记
      

  4.   

    我让他开机启动我的一个service,可却显示我的service空指针,怎么回事啊?
      

  5.   

    你的service在AndroidManifest.xml中注册了吗?
      

  6.   


    有没有在AndroidManifest.xml设置好intent-filter??<receiver android:name=".BootBroadcastReceiver">
    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
    </receiver>
      

  7.   

    这是设置Receiver
    <receiver android:enabled="true" android:name="bli.weather.receiver.BootUpReceiver"
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    </receiver>
    注册 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    public class BootUpReceiver extends BroadcastReceiver {
        public void onReceive(Context context,Intent intent) {  
         Log.e("BootUpReceiver", "BootUpReceiver");
         Intent i = new Intent(Model.MainServiceActivion); 
         //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
                context.startService(i); 
                Log.e("BootUpReceiver", Model.MainServiceActivion);
                Log.e("BootUpReceiver", "BootUpReceiver");
        }   
    }
      

  8.   

      <category android:name="android.intent.category.DEFAULT" />  楼主把这句去掉试试
      

  9.   

    public class BootUpReceiver extends BroadcastReceiver {
            public void onReceive(Context context,Intent intent) { 
        if("android.intent.action.BOOT_COMPLETED".equalsIgnoreCase(intent.getAction())) {
          
         }   }
    }  
     试下吧
      

  10.   

    有一个问题,BootUpReceiver 启动的service必须跟BootUpReceiver 在同一个包里面吗?
    我用它start不在一个包的service就会空指针,在一个包的就不会。我吧category android:name="android.intent.category.DEFAULT"这句注释掉了
      

  11.   

    现在觉得很奇怪,可以启动我的测试service,可是我要用的service却显示空指针,两个service在一个包下面 <service android:enabled="true" android:name="bli.weather.service.MainService">
    <intent-filter>
    <action android:name="bli.weather.service.MainService" />
    </intent-filter>
    </service>
    <service android:enabled="true" android:name="bli.weather.service.BootUpService">
    </service>
      

  12.   

    好奇怪啊,启动BootUpService就正常,启动MainService就不能实例化,然后提示空指针
      

  13.   

    启动MainService提示空指针就不是开机启动的问题了吧。你用其他方式启动肯定也是空指针,找找哪里的问题。