Saving the values temporarily - java

I have a survey report app, where the user will fill in the data (text and images) but in case he wrote half the report while doing the survey and closed the app to continue later all the data is lost, I am kind of new to programming, I tried to search for a way to do it and found the SQLite but I am not sure of the answer because I don't want to save the data in the app as the report will be sent by e-mail, so as soon as the data is sent I want all the values to be deleted from the app

Please take a look at this link Data and file storage overview.
You can also use the interface SharedPreferences (Save key-value data).
If you want to save your data in an online Database, take a look at Firebase, especially Firebase Realtime Database.
Hope you have all the info.

Related

How to save instance of an activity using Jetpack library

I need to store a large amount of data. Let’s say I need to store the list of users and their profile picture when the app going to rotate my app is crashed. Is there any trick how I can store the data?
You can save your data as a file or in Room and read if afterwards. ViewModel is not created to store huge sets of data.
https://developer.android.com/training/data-storage/files
If it is a simple data you can use onSaveInstanceState but since you have a large data, you can store your data using Room and integrate ViewModel class to handle configuration change. Can you post your code?
https://developer.android.com/topic/libraries/architecture/viewmodel

How to get newly updated data only from Firestore?

Always getting whole document while any changes found on Firestore. How to get data that are newly updated only?
This is my data:
I need msg and sendby in order of object(for eg: 2018_09_17_30_40) inside chat on first load and get only the new msg and sendby if data updated
while on get() getting whole document without any order
Note: Code for Android app.
You can store the last fetched date, and only get the objects with date greater than last updated date.
db.collection('groups')
.where('participants', 'array-contains', 'user123')
.where('lastUpdated', '>', lastFetchTimestamp)
.orderBy('lastUpdated', 'desc')
Always getting whole document while any changes found on fire store.
The new Cloud Firestore database has different concepts than Firebase real-time database and should not be confused. There are no field-level permissions or access to a document. It's the entire document, or nothing. Cloud Firestore listeners fire on the document level. There is no way to get triggered with just newly updated data in a document.
Seeing your database, I can say that you haven't chosen the right schema by adding those messages under the chat property.
According to the official documentation:
Cloud Firestore is optimized for storing large collections of small documents.
You should consider create a new collection named messages and store each message as a separate document. In the link above, there are examples of how you can achieve that.

How to avoid "Hack" on Parse current user file on Android

I'm developing a Social/Messaging app for Android on Android Studio using Parse as the backend.
I think I could have a problem with security, because the app let you buy a premium account using your credit card or coins that you get watching ads, in the activity where you update your profile the app saves the new data (from editText) using ParseUser.getCurrentUser.saveInBackground. Root users could modify the currentUserFile and then when the app updates the data, the modified data get updated
My question: does Parse only updates the new data or updates the whole user Object using saveInBackground ?
Is there a way to only update single data as age, gender, etc?
Thanks!
Edit: Problem solved, see comments below

Best practice : when to load data from remote DB

When I make an app, I always wonder when is the best moment to load data from a remote database.
If the app ask for a login screen, then:
Is it better to launch every data from remote DB at his time, and then use them in the app? This way, the app is much faster after the login screen (no more queries needed to retrive some data)
Is it better to load data only when we need to use them (for example, display some data from DB into the app). This way, the login is much faster, but the app can be slower than the first case.
What do you guys think?
It depends on the scenario, but I would go with option 2: First, the user is granted the access and you retrieve the data from your backend when needed.
Imagine a very simple scenario where the user logs in to see a list of products he can work with (add and remove). The solution would consist of 2 screens:
A login screen to manage user access
product list screen to work with products
For me, in a good design each screen has its own resposibility, and each screen should query only the data that it is going to manage.
The login screen responsibility would be only to perform the login and then navigate to the product screen.
The product screen responsibility would be retrieve the products, show them and store them when the user has ended the editings.
If your login screen queries the product data to pass it to the product screen, you are coupling the login screen and the product data.
Anyway, if you have a set of static data that can be used by several screens (for example product categories), you can query them the first time you need them and store them in a cache for further accesses.
Another scenario could be if there can be conectivity problems. In this case the best solution could be to download a set of data that the user can work with, edit them and them upload them to the backend (taking into account the possible concurrency issues).
If you want to logIn your user you have to call the remote DB to authenticate the user. I do not see where you are able to do this without the remote db.
Otherwise you are correct that you should only query the DB if you want to show the data you get.

Android | SQLLite : Pre-created database updating without using SQLiteOpenHelper

My app uses a SQLite database for the information. I have a function that checks to see if the folder and database are already present, if they aren't it will go on the internet ( currently I am using dropbox to store the db file ) and download the database and store it on the sd card, then I it will open the database. The database is writable as it lets the user rate an object. I have two questions.
1.) I would love to provide updates to the database and then have my app update the database if the version number is higher and replace the existing one. I have done some research and from what I have found it is possible to store an xml or json file with the version number of and the just parse the information and if the version number is higher download the new database.
Can someone provide an example of how this is accomplished and whether it is better to use xml or json for this task?
2.) Is there a way to save the rating in the new version of the database when the new is downloaded and accessed?
Thanks
two nights ago I wrote something like that.
pack your database structure as an array in a webservice method by reading field names and field types. the structure of array is arbitrary.
call web service method and you must receive a string that represent a JSONArray object, if you sent it as json with json_encode() method in php.
read structure and make CREATE DB query string with for loops.
execute query, so you must have database.
also you can send alot of information with arrays.
introducing each part is hard, so for each part google it.
don't forget to convert field types to match SQLite types such as VARCHAR=>TEXT, smallint=>INTEGER , ...

Categories

Resources