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 😄 ). However, the problem is as follows:
- search for an Image in
SearchFragment part of MainActivity
- open an image -->
DetailsActivitiy containing a DetailsFragment (I'm talking about phone layout) starts and displays the image
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.
- Mark the image displayed in
DetailsFragment as favorite
- 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:
- 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.
- Don't use a ViewState at all. I do that if the displayed data is sensitive.
- 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.
- Rethink the internal "update" mechanism, i.e. use
onActivityResult() to notify the SearchFragment that the Image has been marked as favorite.
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 😄 ). However, the problem is as follows:
SearchFragmentpart ofMainActivityDetailsActivitiycontaining aDetailsFragment(I'm talking about phone layout) starts and displays the imageMainActivityget's destroyed in background (i.e. because of low memory) then SearchFragment'sSerachViewStateget's stored into the Bundle, containing the search result.DetailsFragmentas favoriteMainActivityandSearchFragmentgets recreated. Since SearchFragment's Bundle contains aSearchViewStatethe 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:
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 inDetailsActivityand presses the back button then itMainActivitygets 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.onActivityResult()to notify theSearchFragmentthat the Image has been marked as favorite.