---
title: "Android Data Backup"  
description: "Hi everyone I am going to explain about android data backup"  
author: "Manoj Pandey"  
published: 2015-03-09  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1635/android-data-backup  
category: "android"  
tags: ["android", "service"]  
reading_time: 3 minutes  

---

# Android Data Backup

Android's backup service allows you to copy your persistent application data to remote "cloud" storage, in order to provide a restore point for the application data and settings. If a user performs a [factory reset](https://answers.mindstick.com/qa/51463/what-to-do-when-you-encounter-activation-error-on-your-iphone-se-after-factory-reset-restore) or converts to a new Android-powered device, the system automatically restores your backup data when the application is re-installed. This way, your users don't need to reproduce their previous data or application settings. This process is completely transparent to the user and does not affect the [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) or [user experience](https://www.mindstick.com/articles/12731/the-importance-of-feedback-to-the-user-experience) in [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding).\

Note-: The backup service is not designed for synchronizing application data with other clients or saving data that you'd like to access during the normal application lifecycle. You cannot read or write backup data on demand and [cannot access](https://www.mindstick.com/forum/33726/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach) it in any way other than through the APIs provided by the Backup Manager.

***Here is an example of Android [Data Backup](https://www.mindstick.com/forum/242/data-backup).***

1. Create an android project with minimum sdk must be greater than 8.

2. Register for your Android Back Service from this link.

![Android Data Backup](https://www.mindstick.com/mindstickarticle/e421e2ba-e4b5-4be6-8acf-401c495a621e/images/22750631-f965-4341-b79c-cf6617228528.png)

\
Then click on Register with android backup service. It would give you your key, along with your AndroidManifest code to copy. Just copy the key. It is shown below:

Your key is-:

![Android Data Backup](https://www.mindstick.com/mindstickarticle/e421e2ba-e4b5-4be6-8acf-401c495a621e/images/0f215fe2-b7ae-44e8-a6c6-6db5caf6c4df.png)

3. Add key value in your manifest.xml file

<application

android:allowBackup="true"

android:backupAgent="MyBackUpActivity">

<meta-data

android:name="com.google.android.backup.api_key"

android:value="AEdPqrEAAAAIErlxFByGgNz2ywBeQb6TsmLpp5Ksh1PW-ZSexg" />

</application>

Android provides BackUpAgentHelper class to handle all the operations of data backup. In order to use this class , you have to [extend your](https://answers.mindstick.com/qa/114593/how-can-you-extend-your-smartphone-s-battery-life-with-simple-tips) class with it. My BackUpActivity class is

```
public class MyBackUpActivity extends BackupAgentHelper {
```

```
 
```

```
}
```

4. Add following code in [AndroidManifest.xml file](https://www.mindstick.com/interview/2588/explain-androidmanifest-xml-file-in-detail)

```
<?xml version="1.0" encoding="utf-8"?>
```

```
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
```

```
   package="com.example.androidbackupexample"
```

```
   android:versionCode="1"
```

```
   android:versionName="1.0" >
```

```
 
```

```
   <uses-sdk
```

```
      android:minSdkVersion="8"
```

```
      android:targetSdkVersion="18" />
```

```
 
```

```
   <application
```

```
      android:allowBackup="true"
```

```
      android:icon="@drawable/ic_launcher"
```

```
      android:label="@string/app_name"
```

```
      android:backupAgent="com.example.androidbackupexample.MyBackUpActivity"
```

```
      android:theme="@style/AppTheme" >
```

```
      <activity
```

```
         android:name="com.example.backup.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="AEdPqrEAAAAIErlxFByGgNz2ywBeQb6TsmLpp5Ksh1PW-ZSexg" />
```

```
 
```

```
   </application>
```

```
 
```

```
</manifest>
```

5. Paste following code in MyBackUpActivity.class

```
package com.example.androidbackupexample; import
android.app.backup.BackupAgentHelper;import
android.app.backup.SharedPreferencesBackupHelper; public class MyBackUpActivity extends
BackupAgentHelper {                static
final String File_Name_Of_Prefrences = "myPrefrences";                static
final String PREFS_BACKUP_KEY = "backup";                 @Override                public void onCreate() {        // A helper class hat can be used in conjunction with BackupAgentHelper       //to manage the backup of SharedPreferences.                                SharedPreferencesBackupHelper
helper = new SharedPreferencesBackupHelper(                  this,File_Name_Of_Prefrences);                                addHelper(PREFS_BACKUP_KEY,helper);                } }
```

---

Original Source: https://www.mindstick.com/articles/1635/android-data-backup

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
