Android application backup and restore? - java

For the application I'm creating, I'd like users to be able to backup their application data (to an SD card for instance). What I mean by application data is the preferences and SQLite database. I'd also like to make it possible to restore the data.
Is it possible to do this with BackupManager? If yes, can someone give me a simple example.

BackupManager is for saving your data to the cloud. To have something backed up to the SDcard, you could write some kind of a service for your application which does this. All the files/dbs/preferences can be written to a folder.
But, this approach also has a risk if the user formats his SD card or deliberately deletes the folder. You can have no control over that.

Related

clear app data without killing application

I need to clear all app data including cache without killing the application. All solutions I have seen either just remove cache data or they kill the application after removing app data. Is there any way to do aforementioned thing without the application being closed?
Android developers save user data mainly in three locations. File System DataBase SharedPreference.
File System
context.getCacheDir();
context.getFilesDir();
context.getExternalCacheDir();
context.getExternalFilesDir();
You can navigate the file system and delete the file you create.
Database
You can use context.deleteDatabase(String name); to delete the database you create.
SharedPreference
context.getSharedPreferences(String name, int mode).edit().clear(); will remove all values in the sharedpreference file.
Indeed, it's your responsibility to find all the files and directories your app creates. I think it's hard to do it exactly right.
And with the application running, it generates new files when you are cleaning the room. So the methods above can provide your user a way to minimize storage usage, but can not really completely remove all data.

Android - Is it possible to overwrite userdata of another app?

I want to update user data of another app from my app. The purpose of this is to update some images that the other app uses. Is this possible?
It depends on where the data/images are saved.
For every app there is a folder named /android/data/package.name to which only that application has access to read and write. No other application has the privilege of writing to that particular folder.
But if the data is saved somewhere else than /android/data/package.name folder, then you can definitely overwrite their data giving that you have proper read/write permissions.

How to save application data for use across users in OS X

I have a Mac Java application that needs to persist data across reboots. The data needs to be saved so that any user has access to it. E.g. an SQLite database file that can be used for all users.
It looks like the /Library/Application Support/ folder is supposed to be used for this, but I'm not able to write to it without making my app run as root or changing the permissions of the file to rwxrwxrwx.
What is the proper way to save application-level data on Mac?
The developer documentation covering this is a bit of a large topic:
https://developer.apple.com/library/Mac/referencelibrary/GettingStarted/GS_DataManagement_MacOSX/_index.html#//apple_ref/doc/uid/TP40009046
https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672
According to the File System Programming guide you should make a specific subdirectory inside /Library/Application\ Support for your app to store app data common to all users on the system. I'd use reverse domain name notation such as com.yourcompany.yourapp or something else unlikely to collide with another app's use of the common directory for this.
You might also look into using an existing app bundler for OS X such as https://bitbucket.org/infinitekind/appbundler rather than hard code paths to file locations.

application size issue

I'm building a dictionary application and I have a problem right now. My application's is 16MB and when I install it on a phone, Database files copies to the data folder and in the manage apps section I see that my application size is 32MB (my app+data folder).
I don't cheat user, I want to say, my app is 16MB, but when user install it , it become 32MB. Why? this is a negative point and I want to solve it. I want my app uses only 16MB in users phone. just that
How I can fix this? I have to read and write in assets folder directly or there is other solution? this is a problem in low storage size phones. how I can fix this?
I am not sure how your database is structured in terms of whether it is a pre-loaded database wherein you just include you .db file with all the data OR is it something where in you push all your DB content with the app and then at the time of app installation you actually install all you data in the DB.
In case of the latter situation you double the size of your app because you already have data content (in files) which you want to use to populate your database (say 16 mb in this case). Then you use these files to actually create your DB file (which is 16mb again) and this doubles the size of the app.
So what you could do is pre-populate your DB content in a .db file and then just use this file directly as the Db file in your app (this will keep it to 16mb). Follow this tutorial :
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Hope this helps.
Not sure I fully understand your situation.
Do you have a roughly 16MB dictionary, that is packaged inside your app as string constants in your code or some resource file or something (to make it 16MB) and then, when your app installs or first launches, you also write this dictionary into your app's database?
If so, then now you have 2 copies of your dictionary around to make it 32MB.
To solve this, either keep only one copy in your app, or download the dictionary from somewhere to get it into your database rather than storing it as a constant in your app.

Save data between different package/apps

I have both a free and a paid app. If the user first tries free version and acquire for example 10 gold and then upgrade to paid version I want him to keep those 10 gold and not do a fresh start.
So is there way to share and access data between apps? And I don't want to save it to root of SD card because user can easily modify it that way.
I think some developers circumvent this by using their paid app just to check the payment (if it's installed, you've paid for it) and keep everything (code wise) in the free version. You could as well just encrypt/decrypt the data written to the SD card. This would as well make it easier for the user to backup/restore those saves (and nothing would be lost in case the app is reinstalled or something like that).
You can create a file in application data folder. And save it there.
/data/data/your_complete_package/your_data_filename
And of course you need to encrypt it with something unique to this phone.
So they wont be able to move this file to another phone to use.
Note that file under app data folder will uninstall together with your App.
I think Android Content providers may solve this problem:
http://developer.android.com/guide/topics/providers/content-providers.html
Content providers manage access to a structured set of data. They encapsulate the data, >and provide mechanisms for defining data security. Content providers are the standard >interface that connects data in one process with code running in another process.
Your app can implement ContentProvider and export data uri you need to share, than your free & paid version can share data through ContentProvider , just like how you access Google Contracts.
BTW,ContentProvider support SQLite & XML , which means you can store it in memory or sd card as you want.
My solution for this would be to maintain some kind of a remote server that holds all the data for users. Users login when entering the app, authenticate themselves with the server, and have all their data available.
Any local solution isn't persistent. What if a user gets his/hers app deleted? if the phone is damaged and the app is unrecoverable?
As a paying user of any app i would like to have my paid data portable through different devices.
Just my 2 cents on the matter...

Categories