I have some issues with this code on my Android project. I need to take the battery percentage level from a service that work in background and when the users open the app I need to pass that percentage to the main activity of the app. In the service I correctly take the battery percentage and I'm able to see it in a toast, but when i try to send the number to the activity I always have 0. This is my code of the **Service**

```
public class MyService extends Service {

private final IBinder mBinder = new LocalBinder();

public class LocalBinder extends Binder {
    MyService getService() {
        return MyService.this;
    }
}

@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

public int b=0, livello;
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent intent) {
        int level = intent.getIntExtra("level", 0);
        b=level;
        if(b!=livello&&b!=0) {
            livello=b;
        }
    }
};

//prendo il livello senza aspettare il broadcast
public float getMyBatteryLevel() {
    Intent batteryIntent = this.getApplicationContext().registerReceiver(null,
    new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    return batteryIntent.getIntExtra("level", -1);
}

@Override
public void onCreate() {
       super.onCreate();
       float a = getMyBatteryLevel();
       livello = (int) a;

       registerReceiver(this.mBatInfoReceiver, 
               new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

       Toast.makeText(getApplicationContext(), "Service Created "+livello,1).show();
}

@Override
public void onDestroy() {
       Toast.makeText(getApplicationContext(), "Service Destroy",1).show();
       super.onDestroy();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
       Toast.makeText(getApplicationContext(), "Service Working",1).show();
       return super.onStartCommand(intent, flags, startId);
}

//funzione che uso solo per passare il livello all'altro file java
public int getBatteryLevel() {
    return livello;
}

```

}

and this is the code of the **Activity**

```
public class SaveBattery extends Activity {

MyService mService = new MyService();
boolean mBound;

public int livello=10;
TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv  = (TextView) findViewById (R.id.tv);

    //se il service non è attivo lo lancio
    if (isMyServiceRunning(MyService.class) == false)
        startService(new Intent(this, MyService.class));

    Intent intent = new Intent(this, MyService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    livello = mService.getBatteryLevel();

    tv.setText(""+livello);

}

//verifico se il service è attivo
private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

private ServiceConnection mConnection = new ServiceConnection() {
    @Override
    public void onServiceConnected(ComponentName className,
            IBinder service) {
        Toast.makeText(SaveBattery.this, "Service is connected", 1000).show();
        LocalBinder binder = (LocalBinder) service;
        mService = binder.getService();
        mBound = true;
    }

    @Override
    public void onServiceDisconnected(ComponentName arg0) {

        Toast.makeText(SaveBattery.this, "Service is disconnected", 1000).show();
        mBound = false;
    }
};

```

}

Anyone can help me?