Why previous data's are missing after every run in App Engine? - android

I am trying to learn Google Cloud Storage with JAVA for some days and i was inserting some data in datastore and the inserted data's could be seen from here //localhost:8080/_ah/admin/ . Now when i stopped this session and again run the backend some weird behavior i saw.
Case 1: When i am running it again my previous data's are gone.
Case 2: If i have inserted 4 data's in the datastore in a session and then in the next session 2 or 3 of my previous data are missing.Here in this case not all the data. And also sometimes one data is missing.
I searched for this and i saw that the local_db.bin will be created in every run. I prevented it by adding the following condition in VM arguments - Ddatastore.backing_store=PATH.
But still i am having inconsistent behavior. Though the local_db.bin file is not being deleted, but the datastore behavior is erratic. (For example sometimes the entities are successfully preserved, and sometimes some of the entities are deleted).Will this happen when i integrate with my android app?

During startup, the App Engine dev server displays the location of the datastore file it is using. I have seen in the past where a different datastore file is used when starting the server each time.
You can copy the datastore file to a location of your choice. Use the datastore_path flag to inform the dev server which data file to use. This will allow the dev server to use the same datastore file each startup.
dev_appserver.py --datastore_path=/data_path/myapp_datastore myapp
You should not see random data disappear from your app as you have mentioned. One thing to keep in mind is that the Google Cloud Datastore uses an eventual consistency model. So, if you are inserting a new record in the same process as returning a list of all records - you may not see that new record until you refresh the page in your app.
There are ways to force strong consistency by using ancestor queries. More on ancestor queries can be found in the documentation:
https://cloud.google.com/appengine/docs/python/datastore/queries#Python_Ancestor_queries

In cause you're developing in Java, you've to provide VM arguments like this
-Ddatastore.backing_store="/path/to/datastore/file/location/local_db.bin"
More here: https://code.google.com/p/android/issues/detail?id=68225
You can also find another solution for custom datastore location using Java dev server in my question.

//localhost:8080/_ah/admin/ shows only data that is used locally on your computer for testing purposes only. It is not linked to the actual Datastore in any way. You should also test your app with actual data after you deploy your app to the App Engine.

Related

How to best handle data models in an an Android App?

I have a college project where the idea is to allow gym-goers to record their progress/evolution in several machines/exercises (e.g. first week I ran 6km in the treadmill in 15 minutos; second week I ran 6.5km, and so forth). I want the user to be able to create an activity plan by selecting several machines/exercises from a list, and each machine/exercise has properties (such as repetitions, muscle groups trained, time, weight, distance, etc).
So, my question is: what is the best way to store the different types of machines/exercises on the apk? Is it to create models for each generic type and load them from a local JSON? Define each exercise outside the app and connect it to a database and have the app fetch the list to the user?
In a prior project I created a Truth or Dare game where the questions (truths or dares) where loaded from a local JSON and turned using a factory to actual questions (using a Question model) to display in-game, but I never found out if that's the best/correct approach.
P.S.: there exists both the possibility that the App is solely local OR that it will be connected to a server + db. Unfortunately, due to the nature of the project I cannot give a concrete answer to this question, but would instead appreciate an answer to both cases...
Thanks in advance!
Using apk's local storage for data storage/retrieval
In such case you can either use JSON for storage/retrieval or android's SQLiteDatabase . If you use SQLiteDatabase for storage your app will contain db file which is a small database embedded in apk
If your data contains multiple entities related to each other then you have to go for SQLiteDatabase as using a plane JSON in such case would not be simple
Using remote storage for data storage/retrieval in apk
In this case you can setup database server in remote machine for your app.
Or
You can use Firebase
It depends what type of app you are making, if user doesn't have to update its exercise progress to remote machine then local SQLiteDatabase would be sufficient in your case

Backup and sync SQLite database with Google Drive logic?

I want the "backup" part to be done in the background and would only start if the user is not using it. I am using android-priority-jobqueue and have made a Job object that would achieve this.
Here are my current problems :
But now I am thinking of how I can make sure that the user is not using the app so that I can run the job. I am also thinking how I can backup or sync the database while the user is using the app like in multiple other apps.
I don't know how I can restore the data back to the app without missing any data. Like for instance, there are two devices. Device 1 backed-up its database into Google Drive. Now, Device 2, being that it had no connection for a few hours, it created new entries into the database. Then it connected to internet and it has to get the other entries from the Google Drive without overwriting the entries it currently has.
I really am confused about when to sync, when to backup, and how they can be flawlessly achieved.
Can anybody please help me
For #2, if you are using GDAA to upload the file, you can pass an ExecutionOptions that allows you to handle conflicts. This lets you implement any arbitrary logic to resolve the upload conflict, e.g. maybe in your case it's to merge contents from both devices. However, note that currently conflict detection is only possible for updating an existing file, not for creating a new one.
For more reference:
https://developers.google.com/drive/android/completion#conflict
https://developers.google.com/android/reference/com/google/android/gms/drive/ExecutionOptions.Builder.html#setConflictStrategy(int)
Sample code for conflict resolution:
https://github.com/googledrive/android-conflict

Leave DB Android created Google Play before publication.

I have an android project which has a local database, when the application starts it syncs with the web service, I have a JSON file containing Countries, States and Cities of Brazil that is imported into the database as the user need this information to register the address of their customers ...
I can not get this information from the Web, because the proposal of the app is to work offline, and when you have an internet connection to send data to server.
Therefore, I was wondering if there is a way to get this data previously entered in the database and not embed them in the first inicilizaĆ§Ć£o, this works, but requires a lot of processing, it takes about 5 minutes on average (this is long ) to do the import.
Any solution?
Thank you!
My previous app has the same problem like this. I give you the solution that I did:
Before release your app, you should embed the latest database (imported by json, call db1) in asset folder, then copy it into application database folder (something like /data/your.package/databases) when initializing app, it only takes some seconds. By this way, you can query data and check user login/register normally.
Whenever device comes to internet, you just download the latest json data and import it into another database file (call db2) on background.If this progress doesn't have any errors, you can replace db1 file by db2 and it can work properly.
There is no other way to do that but you can minimize your payload using gzipinputstream, big cookie model to sync to your server, fast networking library called volley etc.,

Android: Updating local database from an online database

I have an android application that works as an inventory application to different stores (You can search for any electronic device according to certain specs and find which stores sell it and their location). The application comes with a local database, this database needs to get updated through a soap service to have the latest information about the electronic devices, offers and shops. The soap service will get it's data from another database hosted on the web and that gets updated from different sources through a designated website.
The problem we are facing is that we can't figure out the way to update the local database without having the user downloading the whole "online" DB from the web every time it gets updated as that would be bandwidth consuming an the DB can get as big as few MegaBytes.
We came up with the following solutions:
Create Versioned Update Scripts that will have the SQL transactions done on the online DB, the application will download them and run them to update the Local database. The issue with this solution is that if a user doesn't update the application regularly, they will have to download alot of scripts to do the update the next time they are going to update the application, and most likely it will contain a lot of junk scripts (Items get added on an early script, then gets deleted on a later on) .
Download the online DB and replace the local one with it. As mentioned above this can be pretty annoying since the DB size might be a few Megabytes.
Can someone help me with this issue?
TYI
Your best bet would be Google Cloud Messaging for Android (GCM)
http://developer.android.com/guide/google/gcm/index.html
It doesnt get any better than this. This video should get you up and running in no time dude.
http://www.youtube.com/watch?v=51F5LWzJqjg

Android: In-App In-Place Updating

I have an Android app, where a part of the app is a list of data which is currently contained in a string-array (in an xml resource). I currently release updates every so often to the actual app, which do nothing more than update this list of data. (yes, in hindsight this method was a bad idea to start with).
My goal now is to change this so that I will be able to only update that one part of the app that needs to be changed. I have a webserver, and am now serving a JSON version of the data off a URL. So all the app has to do is hit that URL, check if it changed (perhaps using a version number), and then update.
My problem lies in the actual implementation:
Where/how should I store this data? As a raw file? SharedPrefs? Database? [i.e. what are the pros and cons of each]
How can I preform a seamless upgrade where even if something devastating happens during the update [such as a user pulling a battery...], it still won't break the app?
Should the updating code live in a service?
I would separate your data crud into a small background service. Use the provided SQLLite. To verify data consistency you could use md5 checks, database rollback features and most importantly design a small set of tests. One only sending a partial file, i.e. "the broken transmission test", garbage file, etc. Keep it a separate and testable component of your app.

Categories

Resources