Android, when to load user data and where to store it - android

I recently started working on Android apps, and im having a hard time deciding what approach i should use for this issue. For simplicity sake, lets assume we are making an app identical to Instagram. I have a back end server that has all the user data. The user logs in, and is on the main activity and now :
Should i fetch all the user data, all his photos, all his info now (directly after he logs in), and store it in somewhere, so when he visits the profile activity all his info is already on the device, or should i download all his photos and info when he clicks on profile? If its the first option, where should i store his data(photos,ext) after i download it? SQLite ?
Obviously this questions extends to other stuff as well, like should i download all his messages when he logs in, or should i download all his messages when he clicks on the messaging activity. Thank you!
EDIT: I am also new to Stack Overflow, and have been getting some down votes, if you are planning to down vote, could you please comment your reason as well, so i can get better.

This question is a bit too broad to answer properly. In my personal opinion this will depend completely on what you are trying to build. For example, ideally you would be combining local database and remote database for the best user experience. As we know, items locally are faster to load, therefore it will be a better user experience. However you can't store everything locally as you mentioned with messages. Instead in this use-case you would only save the last 10-20 messages. Sql-lite with Room as a wrapper is a great combination for a local database.
Android Basics
Room database

Related

When to store Firebase chat message into SQLite

I know many chat app(one to one) using SQLite locally to store messages
and I also think to store every message in Firestore databases
is not good.
but here I confused
When two users are online and seeing chat at the same time
it is not a problem
but one sent message and another one came after it would be a problem
I mean how to store them into SQLite?
another one does not have a message to store because when he came back
it`s nothing
thank you for advice
Well I don't see any problem saving all messages on database if you want offline integration, just code a way to delete all your messages whenever the user wants. If you're afraid of size growth of your app, I suggest you to make your own test, take a clean install and save 100 messages on your database and see how much bytes the data storage increasead.
You should care more about loading your messages, you'll need to develop pagination aproach to load your data and you'll be fine

Design applications with dynamic data

if the application receives its data from remote server then we should save our data in the local database and have our UI load data from the local database for better UX right? Our UI should not load data from servers directly it will result in bad UX. Now my question is I am developing an e-commerce application and it’s data is very dynamic it can change anytime. The product can go out of stock, it’s price and the discount amount can change etc. So how to keep up with it. If I refresh local database every time user opens application then what will be the benefit of the local database. If any of you had faced the similar situation or worked on any e-commerce applications then please me suggest me better ways. Any help would be appreciated. I do not know if this is a right platform to ask this questions.
There are some solutions. You can use push notifications using Parse, for instance, when your MySQL changes. Or you can use JobManager to enqueue custom synchronization tasks. I recommend you to see this video and check out the video project: https://github.com/yigit/dev-summit-architecture-demo
This reflects your problem very good and it is a very nice solution and, the most important, it is developed by a Google employee.
I hope it helps you!

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.

Syncing online database data with local sqlite database android

I couldn't really find information on this particular problem anywhere even though I know there is a lot of questions and documentation on sqlite so sorry if this is a duplicate.
Anyways, I'm developing an app which logs a user in and performs actions on a mysql database on my website via php scripts. But so that the user doesn't have to wait for a web response for every button they press/every activity launch, I have a sqlite database attached to the app which stores the live information as the app is being used (It uses GPS tracking so this data is stored as well as other things).
I suppose my question is, how much should I store locally to be uploaded later? Should I try and do everything locally after initially logging the user in and just uploading/syncing the data in the user's profile onPause() or something and make use of the lifecycle? Or should I do the opposite and try and do everything live online and get rid of the local sqlite database altogether?
Just wondering if anyone has had experience with this kind of situation and what conclusions they came to.
Thanks for your time,
Infinitifizz
There are some sqlite3-rdiff tools for syncing SQLite databases at mobigroup

Android showing results of the query to the server

I develop app which will download information from Internet server and show search results in ListView. When user clicks on item more detailed information will be shown.
The question is whether to write search results before showing to DB or not? I know that Activity lifecycle can loose all data and some developers recomend to do it safe, but is it really necessary?
Yes, it makes sense to persist the data because if the activity is destroyed and you lose the data while the user has switched to instant messenger or mailer, the user will have to re-download the data from the server, which causes extra traffic and potentially money loss.
Also it doesn't necessarily need to be a DB - you can just use some temporary file. But you do need to persist this data.

Categories

Resources