Build a nice UX to backup and sync your app data on Google Drive (3/3)
Paolo Rotolo
875

Hello I created my first app with Android studio, I need to Backup /restore data each time user add new record to Database, but untill now requestBackup is not working. when I tested by : adb shell bmgr backup <package> adb shell bmgr run adb shell bmgr restore <package> It works, but not automaticly Here my files Manifest — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — <application android:allowBackup=”true” android:backupAgent=”TheBackupAgent” <meta-data android:name=”com.google.android.backup.api_key” android:value=”WWWWWWWWWWWWWWWWWWWWWWWW \> — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — TheBackupAgent — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — public class TheBackupAgent extends BackupAgentHelper { String DATABASE_NAME = “caisses”; String DATABASE_FILE_NAME = “caisses.db”; @Override public void onCreate() { FileBackupHelper dbs = new FileBackupHelper(this, DATABASE_FILE_NAME); addHelper(“dbs”, dbs); } @Override public File getFilesDir() { File path = getDatabasePath(DATABASE_FILE_NAME); return path.getParentFile(); } public static void requestBackup(Context context) { BackupManager bm = new BackupManager(context); bm.dataChanged(); } } — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — Activity add Operation to database — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — mabase.insertOperation(id_client, id_type, IO, Integer.parseInt(date_en_chiffre.toString()), date.getText().toString()); Toast.makeText(getBaseContext(), “Enregistré avec succès, OK”, Toast.LENGTH_SHORT).show(); TheBackupAgent.requestBackup(New_Operation.this); Email : smarthttp@gmail.com

Like what you read? Give Moussa Lhoussaine a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.