Koger
Koger

Reputation: 1923

How to detect when app was restored using Backup Service?

In my app user can choose custom files to be used instead of some default settings. File's info is stored by its URI and I have hard time handling case of Backup Service restoring whole app, when all the restored URIs will be invalid.

App will turn to using default settings whenever it detects invalid URIs (not pointing to custom files), however I would want to inform the user about this fact after restore is performed, so he knows why app is using default settings.

Is there any way to detect when app was restored using BackupAgent?

Upvotes: 0

Views: 340

Answers (1)

Koger
Koger

Reputation: 1923

So far I didn't find any proper tool for detecting when app was restored with use of a Backup Service, however I found a workaround:

context.packageManager.getPackageInfo(myPackageName, 0).firstInstallTime always returns time of install of the current instance of the app, so it is possible to store this time using backed-up SharedPreferences and then comparing it with the time received from packageManager - if it is "newer" than the one stored in SharedPreferences, then it means the app has been restored by a Backup Service.

Upvotes: 2

Related Questions