title: Battery Widget does not update
body: <p>After failing at creating a battery widget, I tried again using a different technique.</p>
  
  <p>After browsing and researching, I decided to use a service and a broadcast receiever inside my <code>AppWidgetProvider</code> class.</p>
  
  <p>My battery value is always null and never changes. </p>
  
  <p>I registered the service in the manifest and see that the service is started.</p>
  
  <p>I added logs and noticed the Start command is called before the <code>onRecieve</code> of the broadcast.</p>
  
  <p>The value changes in the <code>onReceieve</code> but is never changed in the the <code>onStartCommand</code> where I update my view.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Also, where do I unregister the receiever?</p>
  
  <p>My class is below</p>
  
  <pre><code>public class BatteryWidgetProvider extends AppWidgetProvider
  {
      private RemoteViews views;
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
              int[] appWidgetIds) 
      {
          context.startService(new Intent(context, BatteryMonitorReceiver.class));
          /*context.getApplicationContext().registerReceiver(this, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
          ComponentName name = new ComponentName(context, BatteryWidgetProvider.class);
          appWidgetManager.updateAppWidget(name, this.views);
  
          super.onUpdate(context, appWidgetManager, appWidgetIds);*/
  
      }
  
      public static class BatteryMonitorReceiver extends Service
      {
          private RemoteViews views;
          private Integer level;
          private BroadcastReceiver batteryReceiver = new BroadcastReceiver(){
              @Override
              public void onReceive( Context context, Intent intent )
              {
                  String action = intent.getAction();
                  if(action.equals(Intent.ACTION_BATTERY_CHANGED))
                  {
                      level = intent.getIntExtra( "level", 0 );
                      Log.d("BATTERY ON Receieve", "Battery Level is "+level);
  views = new RemoteViews(getPackageName(), R.layout.battery100layout);
  
                  }
  ComponentName thisWidget = new ComponentName(context,BatteryWidgetProvider.class);
                      AppWidgetManager manager = AppWidgetManager.getInstance(context);
                      manager.updateAppWidget(thisWidget, views);
  
              }
          };
  
          @Override
          public int onStartCommand(Intent intent, int flags, int startId) 
          {
              registerReceiver( this.batteryReceiver, new IntentFilter( Intent.ACTION_BATTERY_CHANGED ) );
  
              Log.d("BATTERY Service", "Battery Level is "+level);
  
  
              super.onStart(intent, startId);
              return super.onStartCommand(intent, flags, startId);
          }
  
          @Override
          public void onStart(Intent intent, int startId) 
          {
  
  
          }
  
          @Override
          public IBinder onBind(Intent intent) 
          {
              // TODO Auto-generated method stub
              return null;
          }
  
      }
  }
  </code></pre>
  
  <p>Here is my stacktrace </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start service com.mischel.batterywidget.BatteryWidgetProvider$BatteryMonitorReceiver@40522428 with null: java.lang.NullPointerException
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2473)
  at android.app.ActivityThread.access$2800(ActivityThread.java:135)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1127)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:150)
  at android.app.ActivityThread.main(ActivityThread.java:4385)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
  at com.test.batterywidget.BatteryWidgetProvider$BatteryMonitorReceiver.onStartCommand(BatteryWidgetProvider.java:102)
  at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2456)
  ... 10 more
  </code></pre>