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
Related
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
New to Android app building. I built our company website using php/mysql and my boss had an android app built previously with, I assume SQLlite, or something. Anyway, he wants me to change the database that it's currently linked with to our mysql db. For the life of me I cannot find anything even resembling a connection string or a query in the file system? In my attached screenshot where would I find this information? Or is it not held in this tree at all?
I would assume the data/model folders, but I've searched every single file in those folders. I really need some help.
SQLite is a local db. There would be no connection string, its literally accessed as part of your process.
You should NOT directly connect to a remote db. Doing so is completely insecure, as it would be putting the password for your db into the app. You need to run a web service, and hit that to get your data. The web service then connects to the db.
You should also probably figure out what the actual project is. With SQLite, you would work offline, based off a copy of the data stored locally. With a remote db, offline use is impossible. Being told to replace SQLite with a remote db and your level of understanding of that in this question shows that one or both of you don't understand what the scope of that change is, and you should make sure you're on the same page and what the best way to achieve the actual goal of your project is.
What I need the app to do is to store data in a database and let any user fetch the data. I am not sure how SQLite works but from what I know is that it is server-less. With the database being serverless, how do multiple users, other users, access the same data if it is not stored on a server?
look for backend and a service - parse.com or similar.
SQLite is installed on all android systems, and any app which wishes to create and use a database may do so. This however, is only stored locally on the device.
If you wish to share and synchronize data across multiple devices, that is a different issue all to itself. Indeed it will very likely involve a central server somewhere along the line.
Perhaps start your reading at d.android.com
In Twitter Android App, Once the listview is populated with tweets/items downloaded from server, it never again talks to server to fetch them again. Even if you kill the app and start it again, it still retrieves the same old data.How does twitter store this much of data. Is it using database, storing all downloaded data in a file or caching.
In my app , i have a similar requirement.For now i store the downloaded listview data in a file and then read it whenever the app is started afresh.Is there a better approach or a followed patter for this.
Thank You.
There are three ways to save/persist data on clientside. These being:
SharedPreferences (not ideal with requirements)
File I/O
SQLLite database
As far as I know there isn't a big difference is performance between file-I/O and SQLLite. But SQLLite has a lot of other advantages.
You can query the database, this is more easy then writing it yourself with file-I/O
Manipulation of data is for more easy and less painful (delete/update records etc)
Supports relations between data!
Bottom line, go for SQLLite, it seems more work to setup but you will benefit from this in the future.
I'm developing an Android app as a "proof of concept" for our company. If they like it and think it's worth investing, then we'll move on to bigger things. I'm trying to figure out the best/most practical approach for this.....the basics of the app will connect to our DB and display information regarding a specific customer. For now, let's say we will only pull data from 3-4 tables (but there could be 10+ in the future). If the app doesn't have an internet connection then it should use the local DB. What is the best approach for this? Here's what I was thinking and would like some input/suggestions if possible:
1.) app runs checks internet connection. If exists, check db version (how, through a web service?)..if server db is newer, get latest data. If no internet, use local db.
2.) app parses data and displays it.
If this is correct, then there could be no modifications to the web service that would add fields to a result without changing the app as well. Is there a way for an app to parse fields regardless of how many fields there are?
I've read and walked through the tutorial on google with databases and such (Notepad tutorial) but it seems like the column names are all hard-coded in the parsing class, which I was hoping to avoid.
Sorry if this is confusing but I know I need my app to use a local db to read data, I also know that the app must get data from the server when it can (via onCreate or a refresh button) and copy it locally....Copying it locally is the part I'm having trouble understanding I guess....is there no way of saying "go out and get this result and display it", knowing that those results could mean 5 fields the first time or 1 the next.
Any help/guidance is greatly appreciated!
You probably want to use a SQLLite DB to store your data locally, a ContentProvider to provide CRUD access to the db, and a SyncAdapter to sync with your server when possible. The Sync Adapter also writes to the DB via the ContentProvider. See the SampleSyncAdapter sample in the SDK for an example of how this works. You will be implementing your own ContentProvider, but the sample just uses Android's supplied Contacts ContentProvider.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html