1

Whenever a user installs my app for the first time an instalationID is generated randomly (say Instalationid =123). I am trying to back up this instalationID, so that when the user uninstalls and then installs my app the old instalationID (123) will be assigned to him again, rather than a new one. After all, he is the same user.

I have a shared preferences file, called SESSION_INFO_PREFERENCE_KEY, that holds the instalationID and I try to back up the shared preferences file. The back up manager is:

public class ADCBackupAgent extends BackupAgentHelper {

    // The name of the SharedPreferences file instalation ID
    static final String INSTID = "SESSION_INFO_PREFERENCE_KEY"; //SESSION_INFO_INSTALLATION_UID    

    // A key to uniquely identify the set of backup data
    static final String INSTID_BACKUP_KEY = "inst_id";

    // Allocate a helper and add it to the backup agent 
    @Override
    public void onCreate() {
        Log.i("OnCreate Method","!!!!!!ON create called!!!!!!!!!!");
        SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, INSTID);
        addHelper(INSTID_BACKUP_KEY, helper);               
    }

}

Also, whenever the instalationID is generated for the first time I perform a call to the Back up manager such as:

//this pointing to the current Activity
 BackupManager backUpManager = new BackupManager(this);           
 backUpManager.dataChanged();

For the sake of completenes:

<application 
        android:icon="@drawable/application_icon"
        android:label="@string/app_name"
        android:name="MyAppName"
        android:theme="@style/FragmentTheme"
        android:allowBackup="true"
        android:backupAgent=".ADCBackupAgent"> 

...

<meta-data android:name="com.google.android.backup.api_key" android:value="AEdPqr..." />
</application>

My code works perfectly fine when I do the back up on the local transport (using the bmgr tool), however, when I try to back up the data on Google's cloud strage I get:

04-28 15:12:24.305: W/BackupTransportService(390): Not ready for backup request right now: [OperationScheduler: enabledState=true lastSuccess=2014-04-03/15:10:49 moratoriumSet=2014-04-28/14:43:18 moratorium=2014-04-29/14:43:18 trigger=1969-12-31/19:00:00]

Furthermore, the onCreate() Method is never called.

This does not happen when I back up the data on the local transport, i.e., onCreate() is called and "Not ready for backup request right now" does not appear.

Alan Ford
  • 365
  • 1
  • 4
  • 15
  • I have the same problem, Do you find a way to fix this? – DzungPV Aug 01 '14 at 06:08
  • Actually, I did fix it but I do not know if it will be helpful for you. My problem was that I used an e-mail address, different that the one the app is under, to register for the Android back up service – Alan Ford Aug 01 '14 at 14:05
  • Thank you, but i gave up with it, it don't work on most device, even with non-rooted you can see my other problem here: [link](http://stackoverflow.com/questions/25073520/android-backupmanager-backupagent-not-work-on-root-device) – DzungPV Aug 01 '14 at 14:28
  • I did spend a lot of time to make this work, if you give me more info on how you are trying to make this work I might be able to help – Alan Ford Aug 01 '14 at 17:37
  • Never mind, i have plan use it for Promotion, but due to it don't work instant when you call dataChanged() or requestRestore(), it must schedule and then do it later. Other problem it don't work on all device, at least with my test device. This write by Google: Note: Registering your application with Android Backup Service does not guarantee that it will always back up data using this service from Google. If you support data backup in your application, then it will back up using whichever transport is enabled on the device. – DzungPV Aug 02 '14 at 02:47

0 Answers0