I have an app that creates a directory for backup files on the external storage and automatically creates backup files when the user exits the app. One backup file per week is created and then one backup file that is overwritten all the time with latest info.
The backup files can't be located in getExternalFilesDir since they needs to survive that the user reinstalls the app.
I can't use MediaStorage because it's not an image or video.
I can't use Storage Access Framework to ask the user every time he exits the app to save a backup file.
So how to automatically create persistent backup files with the new Scoped Storage?
(I also need to list all created backup files, if the user wants to restore one of them.)
Backup is appropriate in the case when the user loses the device, buy new, install the app, login and get his data as they were.
Your question is looks like you try to leave on the user device something that he probably doesn't need, as far he deletes the app. If it's the general files like images, music, documents that many apps can view or edit - leave them there and do not care. If it's only your app data - they should live while your app is installed and die when the app is deleting.
It makes sense to back up to the cloud only. In case you don't need a personal server, here is the option: implement syncing with Dropbox or Google Drive. It's the best option just to update the app's data after each closing of the app using the service.
Related
Is there a possibility for iOS & Android to delete all data when uninstalling the mobile application? his does not mean the debug version of a developer on a test device. This scenario should be ensured.
iOS deletes all the data related to your app when the user uninstalls the app.
However, things are little different in Android. Before Android 11, you could have saved the data in device external storage which isn't deleted after uninstalling the app although the internal storage data (Android > data > com.xxx) is deleted.
But with Android 11, you don't need to worry about the external storage data anymore because you have no access to it and hence you can't store anything there. So, you're only left with the internal storage.
So, all the data will be deleted automatically when the user uninstalls the app.
This is done by the OS(Android/iOS) as all the data is deleted when the app is uninstalled.
In addition to this, you should check android:allowBackup and android:fullBackupContent options in your manifest file. Check more info here
If you want to also delete some files that we store in a folder on the sd card? You will not be able to, since those files are no longer your app files but just some files that the app uses and you can consider storing them in a different way.
There are only few questions # so about Android Auto Backup. I have not used this before so went through the documentation first!
https://developer.android.com/guide/topics/data/autobackup.html#Files
Then I made a sample app and managed to add to the list of apps that have been backed up in the Google Drive.
But still I would like to clear things from so because it makes easy to understand than a document.
Here are few points I messed up.
Restore schedule
The device can restore from either its own backups or the ancestral
dataset. The device prioritize its own backup if backups from both
sources are available. If the user didn't go through the device setup
wizard, then the device can restore only from its own backups.
This can go upto 25MB.Let's say I uninstall an app an reinstall it again.Not at what stage it takes the backup? Do i need to follow any technique eg: like a splash till it completes onRestoreFinished()? if there is like 20 MB data? Any good example for this?
Enabling and disabling backup
<application ...
android:allowBackup="true">
</app>
To disable Auto Backup, set android:allowBackup to false. You may want
to disable backups when your app can recreate its state through some
other mechanism or when your app deals with sensitive information that
should not be backed up
This line is in the Manifest so what can be the best way to make it false once the backup task is done.Let's say registration is done and that's all i want to back up.How can I update that tag value at run time?
Is there any way to reset 25MB backup quota by deleting the existing backup?
Thanks
Not at what stage it takes the backup? Do i need to follow any technique eg: like a splash till it completes onRestoreFinished()? if there is like 20 MB data? Any good example for this?
Lucky for us developers, this is done automatically, during the app installation, which can occur in a few situations:
Data is restored whenever the app is installed, either from the Play store, during device setup (when the system installs previously installed apps), or from running adb install. The restore operation occurs after the APK is installed, but before the app is available to be launched by the user.
From restore schedule
This line is in the Manifest so what can be the best way to make it false once the backup task is done.Let's say registration is done and that's all i want to back up.How can I update that tag value at run time?
That is not possible. As you can read in Backup schedule, it is automatically done on a somewhat regular interval. If you have requirements that conflict with this schedule, you have to implement your own backup mechanism.
Is there any way to reset 25MB backup quota by deleting the existing backup?
This is not necessary. Only one backup exists at a time. When a new backup is made, the old one is deleted:
Backup data is stored in a private folder in the user's Google Drive account, limited to 25MB per app. The saved data does not count towards the user's personal Google Drive quota. Only the most recent backup is stored. When a backup is made, the previous backup (if one exists) is deleted.
From backup location
How to check if the app is a fresh installation or a re installation. I want the user to have his history downloaded if its a re-installation like whats app. I thought of writing the user id in the shared preference but that is not possible as the data may get erased once the app is uninstalled. I am already having a folder of my app on the device which is used for image caching and downloading new images, but this is not reliable as the user may delete the folder. What else can I try ???
Obtain the user storage with getExternStorage, then leave a file there that specifies the usage history. The file you save there will survive uninstalls and reinstalls. Of course the user can delete that file but generally they will not, and if you name it properly they will realize it is part of a program.
I'd suggest you integrate with Android's Backup Service.
People switch phone every two years. Some factory reset their device. Some have more than one device. And some share their device with their kids. Linking a user history so that it follows a particular google account is the ideal way to go.
As to your question regarding Facebook integration, I'm afraid I know too little about that topic to be of any help.
I noticed that my app loses the files stored in the device storage after an update from the Market. I use openFileOutput() to fetch a directory to store my important files, as is specified here. I'd expect that these files would be kept between updates, but it does not seem to be the case, at least with Froyo. If this behavior is correct, how should I store my files in a manner that they won't be deleted after an update?
I noticed that my app loses the files stored in the device storage after an update from the Market.
All files are kept around on an upgrade. Files will be deleted if:
the user uninstalls the app
the user uses the Clear Data option in Settings
Also, if you change android:sharedUserId, your files are not deleted, but they will be owned by the previous user ID, meaning your app will be permanently messed up until the user unininstalls and reinstalls.
I'd expect that these files would be kept between updates
They are.
I created an Android app. The app needs some contents (sounds, XML and ...) those user must download from internet. Now, I want to provide service for users which update app version, without losing apps content.
Could someone advice me how to do it?
I you've ever reinstalled an app, you should have seen the dialog by PackageInstaller that says "All user data is preserved." Data you store in SharedPreferences, SQLite database, or SD card are just there and won't be cleared by update.
But if you want to uninstall your app before installing a new one, the only place you can store your data is SD card.
By the way, SD card is also the most appropriate place for storing downloaded files.