Background:
I'm implementing an app that reads info about movies from a web service. That web service return several info about each movie (title,date,poster url, director, actors, etc).
That web service supports pagination, so the movies are loaded in packs of 100.
Implementation:
The idea is to show a grid with all the posters. Auto requesting more items when the user scrolls down.
When an item is clicked the user navigates to a gallery with the detail view of the selected movie, allowing the scroll through the details with a ViewPager.
So the idea is to pass the collection of movies retrieved in the grid to the "DetailedGalleryActivity".
UPDATE: Also is necessary to save the state when the user leaves the fragment in order to handle the fragment lifecycle. You can test it enabling the Developer option: Don't keep activities
The problem
My first approach was to serialize the collection of movies in a json, and pass it as a String extra to the Activity.
But since the list of movies is big, if the user scrolls a lot in the grid, the size of the json is extremely big for a Bundle (see Max size of string data), getting runtime exceptions.
I have checked some answers that talks about persist the data in the SharedPreferences or other persistent storage before launching the detail activity and then access to it from the detail. I find this solution weird because it ignores the mechanisms to pass data between activities with a custom and handmade solution.
What is the best approach to solve this problem?
I am not also sure if this is a good suggestion.
Make another class and add a static method let's name it MovieUtil.
//sample
private class MovieUtil {
private static List<Movies> movies;
public static List<Movies> getMovies();//getter
public static void setMovies(List<Movie> movies);//setter
}
Before you start the DetailedGalleryActivity set the list of movies on MovieUtil.setMovies()
then on oncreate of DetailedGalleryActivity initialize the List by using the MovieUtil.getMovies()
Note: you can clear the list of movies on movieutil when you close the DetailedGalleryActivity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With