I wrote an app that saves and uses data in/from a Cloud Firestore database. I would want to organize more clearly than for the moment my files, for example by using DOs and DAOs.
I know the concept of "DAO" exists in Android Room.
However, the documentation seems to define Android Room as a "local database". So if I understand it well, I shouldn't use it in addition to Firestore?
By the way, it would be the same with Firebase Cloud Realtime Database (a third database system).
Edit :
I didn't understand the notion of "local" database (Room). Tamir, in his answer, corrected me. This question is off-topic.
So if I understand it well, I shouldn't use it in addition to Firestore?
No and this is beacause Cloud Firestore has offline persistence enabled by default:
For Android and iOS, offline persistence is enabled by default. To disable persistence, set the PersistenceEnabled option to false.
This means that you'll have by default a local copy of your database. So there is no need to add another one.
Basically, when you are developing an app there would be some data that you will want to save into locally and other data that you will want to save on remote database, it's not a bad thing to have both remote and local database.
Some example that I can think of for saving your data remotely is to manage users - when a new user will be created you will want to check if the username is not taken, and you can't do it if this data is only stored locally.
And for using a local database - one of the major advantages in the local database vs remote database its the speed of writing and receiving data.
Here is a nice article on the subject.
Related
I'm using OkHttpClient to fetch data from remote DB and display the response to the user.
The user will never make changes to the remote DB. I'm now implementing SQL lite local DB, since I don't think it's good to use APIs to fetch the same data all the time (since the user will send requests frequently and the data change in remote DB will be minimal). My question is how can I update my local DB when remote DB updates/changes.
I have read that updating local DB periodically is bad practice. so, what's the best way to do this?
You have no way to spy on the remote DB "unless you make API calls on a regular basis you need to sample it every few minutes to truly know if it has changed" OR "you assume that every time you use the app your remote DB changed and sync it" if even this is not a viable solution for you and you need it as it updates. You need to use a Realtime DB
I'm very new at programming. I want to make an app where,
1. User1 will make an order (log in as user_profile_1)
2. User2 will work with that order (log in as user_profile_2)
One user shouldn't have access to other's data.
Will SQLite allow me to do that? Seems, database must not run on user's device. And database will always get new records, so we need to update it all the time.
For this case, you have to create a server to store data, I think you should do these things:
Use PHP, NodeJS or some languages server like this to create APIs.
Use a MySQL database or some other database to store data on your server.
Then, different users can log in on their device and you will call your APIs to show what you want.
If you use a SQLite database, the db will be local in the device. The records in the database do not share with other devices.
If you want to access the database from different devices the database will need to exist in a remote server.
You can do differents things:
You can use a database MySql in a remote server with allowed remote access.
You can create a rest api in a LAMP server. You can do this for example with PHP and MySql. You create a GET/POST web page, them pass the data, and the php save the information in the database. You can get the information from the database in the same way, but you should ask to the db in a periodicly time
i want to create an app that uses a database already completed and filled with name and numbers, in detail this app only reads the database and filter some data, for example shows me only "male" contacts in the database. I want to use that app on different phones, so the problem is to incorporate the database in the apk..what kind of database i can use?
You can store the database on a web server and get the data at first run of your app to store it locally. You can find a good tutorial for retrieving data from server at http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/.
Document Orientated Database - A document-oriented database or document store is a computer program designed for storing, retrieving, and managing document-oriented information, also known as semi-structured data.
I am developing an Android application where users will see lists of Groups and join 1-* Groups. Within the Groups will be members and users can message each other within the group they have joined. Sending messages 1 person to many and reply all.
I want this to support multiple devices. So, if i join a group and someone sends me a message, i want to see that message on my phone and tablet. If both have the app installed.
I want the user to be able to see group details while offline.
I have been doing some research and drawing diagrams on how this could work.
What are my options for how to set this up with a remote database?
Here are a couple of the options that i have finally narrowed down to.
Have the remote DB store everything. Have a local DB on the device that reflects the remote DB. Have the remote DB contain a version number. At some point, either scheduled or triggered, the app compares the version numbers in the local and remote and if the local is out of date it will update to the current remote DB.
Have the remote DB store everything. Have a local DB on the device that reflects everything in the remote DB except the messaging system. This would behave similar to #1. Except the tables and stuff that are related to the messaging system would "somehow, gcm maybe" send a message to all devices associated with the user that a message relating to the user has changed and the app will then update to the most recent version of the remote messaging tables in the remote database. Then their local database contains the new data and their "message box" would be updated.
What would be the best way to do this? How is this done currently in most systems? Are there more options then what i listed?
Remote DB: MySql
Local DB: sqlite
I am aware of some similar questions here on SO, but i am wanting to know if either of these options or something else would be best for my specific scenario. Mainly how to handle the messaging part.
Thanks
I think Option 1 is a pretty standard way of handling this problem.
A DB version # could work, but if it changes frequently you will end up resync all the data very often. Its probably better if you just store "Last Modified Date" on records and only pull down things that have changed since the last sync. That way you can return a smaller set of new records.
You would only want to pull down public information (the groups) and the information specific to the user. The remote DB would have everything, but the local DB would only consist of data that is related to the user.
I found this tutorial that walks through how this might be implemented using php on the remote server for API access. You could streamline this process by using an ORM or "Out of the Box" API solution.
I'm sure there are more elegant solutions out there for syncing a local Android DB with a remote but this is likely the most practical approach for the non-enterprise solutions.
I am new to Java and Android. I am just beginning work on an app that will save information to a server that someone else from within the same company can retrieve using the same app from a different android device. I know how to simply store data on a server using simple php scripts but this is a bit more complex and involves one user writing information to the server, while another user can see / download it. Within a company there would be multiple users who have acceess to this data. So my question would be, whats the best way to implement a company-wide database that ONLY members of the same company can have access to? Sorry if this seems obvious to some of you. I am just getting started and I have 7 books on android programming and none of them describe how to do quite what I am trying to do.
To do this you need to use Android network services to access data. In other words to retrieve a networked database information your device will connect to your service with a specified URL and arguments. In turn, the service will reply with the required data, say may be in XML format. All your app needs to do is parse the XMl and display the date as desired.
Same thing applies to putting data into the server, in this case however the data will be sent as arguments to the network service URL and the service will handle the persistence to a database.
My advise is to do a Google search of the keyword "Android Network Services".