ViperArchitectureExample icon indicating copy to clipboard operation
ViperArchitectureExample copied to clipboard

Favor an Image

Open sockeqwe opened this issue 9 years ago • 1 comments

Hey, I found minor problem when marking a Image as favorite. I don't know if you are aware of that and just ignore that issue (I ignore such "issues" most of the time :smile: ). However, the problem is as follows:

  1. search for an Image in SearchFragment part of MainActivity
  2. open an image --> DetailsActivitiy containing a DetailsFragment (I'm talking about phone layout) starts and displays the image
  3. MainActivity get's destroyed in background (i.e. because of low memory) then SearchFragment's SerachViewState get's stored into the Bundle, containing the search result.
  4. Mark the image displayed in DetailsFragment as favorite
  5. Press the back button --> MainActivity and SearchFragment gets recreated. Since SearchFragment's Bundle contains a SearchViewState the ViewState will be restored which contains the data from before favoring the Image. That means that the Image gets displayed NOT as favorite while it should be displayed as favorite since it has been marked as favorite by the user.

You can reproduce that issue by enabling "Don't keep Activities" in the developer settings of your device.

I see 4 solutions for that problem:

  1. Simply ignore that "issue" since it happens rarely and if there is no sensitive data most of the time the user of your app doesn't notice that "issue" anyway.
  2. Don't use a ViewState at all. I do that if the displayed data is sensitive.
  3. Use a RetainingViewState. By doing so the view state will never be stored into the Bundle and data will always be reloaded when activity / fragment gets recreated. But in that brings another problem: when the user is in DetailsActivity and presses the back button then it MainActivity gets recreated and displays the initial state, but the user would expect that the previous search result gets displayed. A workaround would be to save the latest search string into fragments bundle and then rerun the search query.
  4. Rethink the internal "update" mechanism, i.e. use onActivityResult() to notify the SearchFragment that the Image has been marked as favorite.

sockeqwe avatar Sep 05 '15 16:09 sockeqwe

Hi, thanks for your help. Yes I thought about it for a minute before. Well, for the simplicity and clarity of this project (example of an architecture) I will say that it's a minor issue. But for production application it has to be rethought. I like your 4th advice, or something similar.

lurbas avatar Sep 05 '15 21:09 lurbas