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
    1.9K+ Learners
    4.49  (80)
    Become Full Stack Developer
    1 hrs
    Beginner
    45.9K+ Learners
    4.28  (1029)
    Bitcoin for Beginners
    1 hrs
    Beginner
    6K+ Learners
    4.49  (338)
    Pygame Basics
    1 hrs
    Beginner
    4.8K+ Learners
    4.37  (119)
    Inheritance in Java
    1 hrs
    Beginner
    3.7K+ Learners
    4.63  (142)
    Tic Tac Toe Python
    1 hrs
    Beginner
    2.2K+ Learners
    4.64  (58)
    Anaconda Python
    2 hrs
    Beginner
    2.6K+ Learners
    4.62  (106)
    Operators in MySQL
    2 hrs
    Beginner
    6.6K+ Learners
    4.51  (239)
    Advanced SQL
    1 hrs
    Intermediate
    20.2K+ Learners
    4.49  (921)
    Errors in Java Programming
    2 hrs
    Beginner
    2.6K+ Learners
    4.49  (65)