Recently we worked with big databases under android, and during that I met query optimization problems when using subqueries.
From my previous experiences with MySQL I thought, the database engine optimization is always the best, and there is no way, that multiple queries from program code is better, but I ended running multiple selects in a loop in this case for the best result.
When you release a newer version of your application, on update the android system identifies from the package name and version number, that the user has an older version installed. During updating not all data of the previous version is overwritten, databases, preferences, previously downloaded/created files on sdcard or internal storage remain unchanged. If there are any incompatibility with the old version of these, is must be taken care of.
First of all, files on the external storage can be lost or corrupted due to many other reasons, so version incompatibility is just one more reason to check those files before using them.
However the internal storage is theoretically not modified by external sources, if there are version incompatibilities, you have to check the state of this files too.
The internal storage of an android device is very limited, so if your application downloads or somehow generates a large amount of data to store, you should save it on the external storage, the sd card. Even 1mb of data takes much space compared to the whole internal capacity on most of the current devices. The sd card has a bigger magnitude, and it is even expandable.
Even when storing data on the sd card you should limit the space your application can use up. For example if you cache images for an application you should track the usage the images and when the sum size of them exceeds a given limit, delete the the oldest used one.
When developing for API Level 8 (2.2) the directory get by the getExternalFilesDir() method can be used for storing files. Files stored here will be automatically deleted when the application is uninstalled.
In android it is highly important to use transactions when working with databases.
First, in android database operations - especially writing - are very slow. Batching them into transactions will make them much faster.
Second, the database remains consistent under any circumstances. The database system makes sure to all the operations in a transaction take effect, or on error, rollback all of them.
If you are used to other platforms like PHP+MySQL where the code usually runs on a powerful server, witch is not likely to stop execution "unexpectedly", you can be surprised how much it affects the performance in android.
The android system can kill apps/threads/activities and so interrupt database usage, the battery can discharge or can be removed etc.
The implementation is very simple, using 3 methods in the SQLiteDatabase class:
Today we wanted to test ways, to optimize the download of files to android phones.
The first way we tried, is the most obvious method of using a little less of everything (bandwith, battery, cpu, backlight, time? etc), compression. Image source.
But what about speed? Is it worth to sacrifice the app's speed for using less bandwith? How much slower is compressing/decompressing files on a phone anyway?
Read on to find out.
As a possible solutions mentioned in previous article Leaving an Android application the Application object can come handy. If you want to store data, global variables that needs to be accessed from everywhere in the application, from multiple Activities, in other words is you want to maintain a global "state" of the whole application the Application object can help.
For this we must make a class which extends the Android.app.Application class add our own methods to it, and define this class in the AndroidManifest.xml as below:
So the other day, I was asked to check out how we could use soap on Android, preferably with ksoap2 for android, and a public SOAP Web Service. For the latter the TopGoalScorers web service was chosen.
Ever wanted to have a different flow of actions on the second or third run of your app? I had that many times, in almost every project that I haver worked on. So here is a little snippet, that you can use to store, and check the fact, if this is the first run of your app. You can modify it easily, to suit your needs.