Mutable LiveData not updating UI when the app is maximised from background

79 Views Asked by At

I made an http request and started a progress dialog then I send the app to background by pressing home key.After a few seconds I returned to the app, then the loader is not dismissed and data is not updated in the UI.

Track.java

public class Track extends AppCompatActivity {
    private ActivityTrackBinding binding;
    private TrackerAdapter adapter;
    private RecyclerView recyclerView;
    private BeneficiaryViewModel beneficiaryViewModel;
    private NotificationAlerts alerts;
    private Dialog progressDialog;
    private ArrayList<TrackResponseData> trackList;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_track);
        binding.setLifecycleOwner(this);
        binding.setClickers(this);
       
        beneficiaryViewModel.getLoadingError().observe(this, errorMsg -> {
            if (errorMsg != null) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                Toast.makeText(this, "" + errorMsg, Toast.LENGTH_SHORT).show();
            }
        });

        LiveData<ArrayList<TrackResponseData>> trackLiveData = beneficiaryViewModel.getTrackResponseLiveData();
        trackLiveData.observe(this, trackResponseData -> {
            trackList = new ArrayList<>();

            trackList = trackResponseData;
            if (trackList != null && trackList.size() > 0) {
                adapter = new TrackerAdapter(this, trackList);
                recyclerView.setAdapter(adapter);
            }

        });
    }
  
} ```
0

There are 0 best solutions below