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.6K+ Learners
    4.49  (205)
    Become Full Stack Developer
    1 hrs
    Beginner
    64.9K+ Learners
    4.26  (1331)
    Bitcoin for Beginners
    1 hrs
    Beginner
    6.8K+ Learners
    4.52  (414)
    Pygame Basics
    1 hrs
    Beginner
    5.7K+ Learners
    4.32  (185)
    Inheritance in Java
    1 hrs
    Beginner
    4.5K+ Learners
    4.49  (268)
    Tic Tac Toe Python
    1 hrs
    Beginner
    2.7K+ Learners
    4.49  (79)
    Anaconda Python
    2 hrs
    Beginner
    3.8K+ Learners
    4.36  (297)
    Operators in MySQL
    2 hrs
    Beginner
    8.1K+ Learners
    4.48  (448)
    Advanced SQL
    1 hrs
    Intermediate
    28.6K+ Learners
    4.48  (2096)