Android - Offline Data Architecture for Thousands of Data - android

According to Yigit Boyar excellent talk at Google IO 2016, the Mobile App should be usable whether online or offline. On top of that, the data should only come from disk (local storage) to display on screen.
Currently I am implementing e-book store Android app. In my App, I would like to pull data from network about 10 books to show in the list (RecyclerView).
With endless scrolling feature (like Facebook), the app will pull more data from the network when the user scrolls down to the end of the list.
If I keep all the data in local storage (sqlite database), the database will be loaded with thousands of records of books eventually.
Is it normal to store thousands of records in the local storage just only for offline support?
So should I keep the data in Local Storage according to Yigit Boyar's guidelines? Or is it enough to be based on Network cache (references by this article)?
Is there any other solutions that you would like to suggest for my scenario?

It is essential to provide local storage for the eBooks, as the users can read at anytime and anywhere once they downloaded the book.
You can separate the eBook data into two: one for the list and other for detail, in a way that the data for the list is as minimal as possible -- only the required fields for the list. Only if the user clicks on a book and goes to the detail page, download the entire data of the single book.
So storing 1000s of books data wouldn't take more storage as you are storing only minimal data required for the list.
And you can purge the old data based on Least recently accessed books after a certain time period, say, every week or month.

Related

Android: store data locally or not?

My Android app is fetching data from the web (node.js server).
The user create a list of items (usually 20-30 but it can be up to 60+). For each item I query the server to get information for this item. Once this info is fetched (per item), it won't change anymore but new records will be added as time go by (another server call not related to the previous one).
My question is about either storing this info locally (sqlite?) or fetching this info from the server every time the user asks for it (I remind you the amount of calls).
What should be my guidelines whether to store it locally or not other than "speed"?
You should read about the "offline first" principles.
To summarize, mobile users won't always have a stable internet connection (even no connection at all) and the use of your application should not be dependant on a fulltime internet access.
You should decide which data is elligible for offline storage.
It will mainly depend on what the user is supposed to access most often.
If your Items don't vary, you should persist them locally to act as a cache. Despite the fact that the data mayn't be really big, users will welcome it, as your app will need less Internet usage, which may lead to long waits, timeouts, etc.
You could make use of Retrofit to make the calls to the web service.
When it comes to persisting data locally within an Android application, you can store it in several ways.
First one, the easiest, is to use Shared Preferences. I wouldn't suggest you this time, as you're using some objects.
The second one is to use a raw SQLite database.
However, I'd avoid making SQL queries and give a try to ORM frameworks. In Android, you can find several, such as GreenDAO, ORMLite, and so on. This is the choice you should take. And believe me, initially you might find ORMs quite difficult to understand but, when you learn how do they work and the benefits they provide us, you'll love them.

Android online dynamic database

I am new to Android programming and I want to make an online database with information and pictures. In our case we are making app that stores recipes and their pictures. More recipes and pictures will be added in the future therefore it will use Internet to fetch data.
Question:
What is the best practice to store pictures - both old and new ones that will come in the future? On the database itself or on app? And does that mean if we add new recipes would consumer have to update the app if we store it on the app itself and not on web database?
As per my opinion the best practice would be keeping data and images on server and fetching it on real-time as per user need. As saving all images in application and updating more late on would increase the size of application.
You can create local database and cache for your images in which you can store data and images as user goes on accessing your application section, so that user can re-access those sections again in offline mode, but for new data user has to go online, you can instruct user where he would need internet access. Besides this you also need to specify some checkpoints in your flow where application should sync with cloud and update local data.

Android - online offline synchronization of large SQLite database

I am developing an Android application to collect the store (Grocery) information.
The application have modules to create store, set it's attributes like address, lat lng, operating hours, manager details, building photos, etc.
Once the store is created user need to list down the assests of that store by clicking photos and providing it's details.
To store all this details, i have around 15 SQLite tables.
Now i want to implement feature of 'Synchronization', all this captured details need to send to server whenever connection is available otherwise detail should be stored locally and whenever connection is available it should move to server.
Also, please note that the number of tables may increase up to 40 as application grows.
I searched for the solutions/approaches for this on Google but in most of the article or example they have mentioned for small scale application having small data.
I have also implemented synchronization feature for small datatable (2 tables), where i checked for last updated timestamp on server and local and if it's different then we synchronize the data. I don't this i should use this approach for such large scale and large database.
I have one approach which doesn't depend on numbe of tables.
I am planning to have single table which store the following data
id
URL
request header
request body
Now let's say connection isn't available while sending request so it will be stored in table. Whenever connection is available it start reading the table and execute the request, on success it will remove the entry from table. With this approach we need only one table in SQLite.
The problem with this approach is when we want to retrieve data offline how we can do that? Do we need to have local database schema same as server?
Please guide.
Thanks
If you are syncing data with a server and you are removing local storage data ,which is incorrect as per my knowledge ,in this case your app does not work offline.So for that when you sync data to a server at that time maintain some flag which data is synced.And then next time just check flag status if it's synced then do not synced data otherwise do syncing.
I hope this solves your problem.

Web server best practices

I need a suggestion on a design decision.
I am creating a ecommmerce app and have a lot of items (>10000) to show in my app. Now here are the 2 options I have
1) Get all the items information from the server and save in local db and synchronize the information every time (let say 15 min)
2) Get the information every time from the web server (through rest api).
There are pros and cons of both the methods. Using local db I can get fast results and less server bandwidth but will have to handle synchronization
With second approach, I will have a lot of server request to and free and load on server.
I would also like to know how does other apps like amazon and flipkart handle this. Do they save in local db or request server every time.
What you should be looking for is a mixed design between local and remote.
In terms of data types there are two major types:
blobs 'binary large objects' for example: images, videos ...
and small data (usually json/xml representation of the items).
Amazon and other web apps provide fresh data every time the app loads, and at the same time keeps a local copy of the data incase the app went offline, or sometimes even use that data in the next load while waiting for the backend.
On the other end those app maintain a cache level for large data so that they don't have to load it more than once.
But the key for this to work is to have a very fast backend that contains many features to improve its speed including:
cloud front end that allows users to communicate with the closest server around them.
memcached or any other caching technology that will keep the info about the items in the RAM in the servers and not having to query the database to get them.
what usually happens is that the backend ensures that its data always loaded in the ram/cache by ether querying the database every specific time or by pushing to cache every time an insert/delete/update happened to the database.
Here is how Twitter is doing it
One last note Your app shouldn't take longer to interact with more than a web page, its not acceptable for native apps to take longer than web apps to allow the user to interact with them.
Only load what you want to show, but cache intelligently.
For example; an image for a product isn't going to change very often, but the amount of items available for a very popular item can change every second. Decide on a case by case basis what piece of information to refresh and when.
You definitely don't want to pull down everything from your server every time someone launches the app. That does not result in lower bandwidth. It will melt your server, eat up their data plan, and fill their phone storage with products that they will never see.

Android saving user's choices as favorites

I am developing a music app wherein a user can select choices of songs to play. One feature I want to implement is to save a song as favorite. Once favorite is clicked upon, it should save the user's choice and display it next time when the user logs in. None of the data is stored on the app. Everything is fetched from a server. What I intend to store is just the names of the songs. I read the Android Documentation http://developer.android.com/guide/topics/data/data-storage.html for various storage options and those which seem applicable to my case are:
Internal Storage
Database SQLLite connections
as these will store the data private to the application.
Which among these should I use? Are there any other suggestions?
How did you populate the song list? Did you have any cache or you just fetch it from the server every time? To improve the performance and be able to use your application when there is no internet connection - at least can view the song you have ,I suggest you have to provide some sort of cache. Once you have the cache, SQLite is the way to go, for both song data and favorite data.
Both of them works fine. But since your data will be a single text, i would recommend Shared Preferences, which keeps the data as in XML format and it's easy to use.

Categories

Resources