lundi 13 février 2017

How to update UI for callback received while app is in background?

I am creating an android application using MVP architecture. I have created Presenter and Interactor classes. I am struggling to update UI when app is in background and comes back to foreground.

Let's consider following scenario.

Button on UI is clicked and presenter is notified about it. Presenter asked Interactor to provide data from backend. By the time Interactor provides result to presenter somehow UI is in background. How can I save the state of it and change UI components once app is in foreground.

I tried doing following things:

  1. Using flags (turn on the flag and check in onResume to call the method that supposed to be called when callback received. But problem is that let's say if I have 5 different services that can be called by presenter which has different callback then I will require 5 flags which I don't like it)
  2. Using JAVA reflection (Store the name of method be called stored in HashMap with parameter

Is there any better way to achieve this?





Aucun commentaire:

Enregistrer un commentaire