Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store large application data on android devices?

I'm currently facing a problem where I should store my object structure on the android device.

The usecase: I'm starting a call to an applicationserver (with the great help of AsyncTask), get a well known response (xml-response) from the server, parse the data and transform it finally into my object structure (highly complex class diagram with many associations between the classes). So far it's working, thanks to the great XMLPullParser ;) I'm wondering where to store (and of course share) the fetched data between my activities... I already know that I can use sqlite, but I do not have an or-mapper (like hibernate in the j2ee environment). I'm also not allowed to store this sensitive data on the device (in sqlite or file system), so my first approach was to store this data in a singleton (which is of cource being held in memory...). But what happens when system is getting on low memory, can android "destroy" the data stored in my singleton? I already read about extending the android.app.Application class... So what is the best way to securely store object data (called from "webservice") on android devices?

BTW: Android development is that cool! We are currently porting a Windows Mobile 6.5 App to Android and iPhone, and my colleague (reponsible for iPhone-dev) is complaining all the time^^

like image 634
tim.kaufner Avatar asked Nov 23 '10 08:11

tim.kaufner


People also ask

Where do apps store data in Android?

Every application in the device has some private storage in the internal memory and you can find this in android/data/your_package_name directory. Apart from this internal storage, the rest of the storage is called the Shared Storage i.e. every application with the storage permission can access this part of the memory.

What is the best way to store data in Android?

Shared Preferences is the easiest to use, especially if you want to store discrete primitive data types. However, internal and external storage is best for storing files such as music, videos, and documents, while SQLite wins if you need to perform fast searches and queries on your data.

What are the three ways of storing data in Android application?

Android provides several ways to store and share data, including access to the file-system, a local relational database through SQLite, and a preferences system that allows you to store simple key/value pairs within applications.

How do I save app data on Android?

Backup options. Android provides two ways for apps to back up their data to the cloud: Auto backup for apps and Key/Value Backup. Auto Backup, which is available on Android version 6.0 and higher, preserves data by uploading it to the user's Google Drive account.


1 Answers

Regarding an OR mapper, I came across OrmLite the other day. It is a general ORM tool for Java, but it also has some special adaptations that makes it work for Android. I haven't had time to test it myself yet, but it looks promising :)

As for storing sensitive data on the phone, you really don't have the option of storing it only in memory (using some kind of singleton as you suggested). As soon as your application goes to the background, it can be killed instantaneously, so you have to persist what data you want to keep in some way. That being said, if you save data to Internal Storage, this will not be available for any other app on the phone (given that the phone is not rooted, because if is rooted this is easy to get around). I do believe that this same goes for data you store using SQLite, but I'm not 100% certain, so I won't guarantee it.

But basically, if you are sure that your app will only run on non-rooted devices, you should be pretty safe saving your data to Internal Storage. And if that isn't good enough, there there is the javax.crypto package, but I've never used that so I can't really say anything about it.

like image 100
Julian Avatar answered Oct 19 '22 14:10

Julian