BroadCast Receiver is not Refreshing the Data on the Change of PowerSource of Mobile Battery

I am using the BroadCastReceiver to Show the Data of the battery PowerSource by which it is providing the Data. I have used Fragment to Show the Data. I am Able to get the Data and Set it to the Required field but it is not Refreshing on the Disconnect of the PowerSource.How can this issue be Solved?


public class BatteryFragment extends Fragment{

    FragmentBatteryBinding fragmentBatteryBinding;
    BatteryFragmentVm batteryFragmentVm;
    List<PojoMain> batteryData;
    RecyclerAdapter recyclerDeviceAdapter;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        fragmentBatteryBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_battery, container, false);
        batteryFragmentVm = new BatteryFragmentVm(getContext());

        return fragmentBatteryBinding.getRoot();

    //get Battery Power Source
    public static String isPlugged(Context context) {
        Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

        String powerSource = "";

        if (plugged == BatteryManager.BATTERY_PLUGGED_AC) {
            powerSource = "Plugged AC";
        } else if (plugged == BatteryManager.BATTERY_PLUGGED_USB) {
            powerSource = "Plugged USB";
        } else if (plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
            powerSource = "PLugged Wireless";
        } else if (plugged == BatteryManager.BATTERY_STATUS_DISCHARGING) {
            powerSource = "Discharging";
        } else {
            powerSource = "status unknown";

        return powerSource;

    public void retrieveBatteryData(Context context) {
      //  batteryData.clear();
        batteryData = new ArrayList<>();

        batteryData.add(new PojoMain("Power Source", isPlugged(context)));

                .subscribe(pojoMains -> {
                    recyclerDeviceAdapter = new RecyclerAdapter(batteryData, getContext());
                    fragmentBatteryBinding.batteryRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));


    public void onResume() {



public class BatteryFragmentVm {
    Context context;

    public BatteryFragmentVm(Context context) {
        this.context = context;

    public Observable<List<PojoMain>> loadBatteryData(List<PojoMain> string) {

        return Observable.just(string)


Why the data received are not changed on the change of the power source?How can this issue be solved?