Android

Android Data Backup

Android Data Backup

You may have noticed that you can easily back up all your data on your Android device. You can also implement the backup facility on your application. To do that you will need to specify the keys in the AndroidManifest.xml file. 
You can refer to the following example for a better understanding:
1.Let’s start by creating an application in Android Studio under a package com.firstapp.ashulakhwan.greatlearning

2.In the second step, you will need to register your application on Google backup services.

3.After registration, modify the AndroidManifest.xml file with the following content:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.firstapp.ashulakhwan.greatlearning" >

   <application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:backupAgent="MyBackUpPlace"
      android:theme="@style/AppTheme" >
      
      <activity
         android:name="com.firstapp.ashulakhwan.greatlearning.MainActivity"
         android:label="@string/app_name" >
         
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
         
      </activity>
      
      <meta-data 
         android:name="com.google.android.backup.api_key"
         android:value="AdAPqsEABAAIEzlxFWyGgNzywqBe2b6TsmLsp5KshhPA-ZSwgj" />

   </application>
</manifest>

4.Next, you will be required to create a backup agent class in the same AndroidManifest.xml file.

import android.app.backup.BackupAgentHelper;
import android.app.backup.SharedPreferencesBackupHelper;

public class MyBackUpPlace extends BackupAgentHelper {
   static final String File_Prefrences = "my_files";
   static final String PREFS_BACKUP_KEY = "CREATEBACKUP";
   
   @Override
   public void onCreate() {
      SharedPreferencesBackupHelper helper_tool = new SharedPreferencesBackupHelper(this, 
      File_Prefrences);
      addHelper(PREFS_BACKUP_KEY, helper_tool);
   }
}

5. The last step will include the testing of the application to verify the results. 

Top course recommendations for you

    Backtracking Algorithm
    1 hrs
    Beginner
    2.8K+ Learners
    4.57  (327)
    Become Full Stack Developer
    1 hrs
    Beginner
    68.2K+ Learners
    4.27  (1389)
    Bitcoin for Beginners
    1 hrs
    Beginner
    7.1K+ Learners
    4.54  (474)
    Pygame Basics
    1 hrs
    Beginner
    5.9K+ Learners
    4.4  (228)
    Inheritance in Java
    1 hrs
    Beginner
    4.7K+ Learners
    4.52  (320)
    Tic Tac Toe Python
    1 hrs
    Beginner
    2.8K+ Learners
    4.5  (96)
    Anaconda Python
    2 hrs
    Beginner
    4K+ Learners
    4.37  (349)
    Operators in MySQL
    2 hrs
    Beginner
    8.4K+ Learners
    4.51  (519)
    Advanced SQL
    1 hrs
    Intermediate
    30.1K+ Learners
    4.5  (2548)