0

in my app I want to make a service start when boot completed, and I control this option progrmatically, the service start on boot but force closes and restart it self I dont know why

here is my logcat

04-11 22:26:04.999: E/AndroidRuntime(2256): FATAL EXCEPTION: main
04-11 22:26:04.999: E/AndroidRuntime(2256): java.lang.NullPointerException
04-11 22:26:04.999: E/AndroidRuntime(2256):     at technologysociety.socialsaddict.ServiceSocial$6.handleMessage(ServiceSocial.java:156)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at android.os.Looper.loop(Looper.java:130)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at android.app.ActivityThread.main(ActivityThread.java:3835)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at java.lang.reflect.Method.invokeNative(Native Method)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at java.lang.reflect.Method.invoke(Method.java:507)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-11 22:26:04.999: E/AndroidRuntime(2256):     at dalvik.system.NativeStart.main(Native Method)

and I'm controlling this option with a check box here is it

StartUP.setOnClickListener(new OnClickListener() {


        //Start of on boot
      @Override
      public void onClick(View v) {
                //is StartUP checked?
        if (StartUP.isChecked()) {

             PackageManager pm  = MainActivity.this.getPackageManager();
                ComponentName componentName = new ComponentName(MainActivity.this, StartUP.class);
                pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                                PackageManager.DONT_KILL_APP);
                Toast.makeText(getApplicationContext(), "activated", Toast.LENGTH_SHORT).show();


        }else{

              PackageManager pm  = MainActivity.this.getPackageManager();
                ComponentName componentName = new ComponentName(MainActivity.this, StartUP.class);
                pm.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                                PackageManager.DONT_KILL_APP);
                Toast.makeText(getApplicationContext(), "Deactivated", Toast.LENGTH_SHORT).show();
        }

      }
    });

and the broadcast reviver class here

  public class StartUP extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
           // This method is called when the BroadcastReceiver is receiving

           // Start Service On Boot Start Up
           Intent service = new Intent(context, ServiceSocial.class);
           context.startService(service);



    }
}

also my manifest I have this :

<receiver android:name="StartUP" android:enabled="false">
        <intent-filter >                
            <action android:name="android.intent.action.BOOT_COMPLETED"/>                
        </intent-filter>
    </receiver>

1 Answers1

0

You need to find out what is null on line 156 of ServiceSocial.java, and either find out why it's null if it's not supposed to be, or accommodate the case where it is null if null is acceptable there.

Then read this: How to read and understand the java stack trace?

Community
  • 1
  • 1
Brodo Fraggins
  • 628
  • 5
  • 14