Generate backup on Google backup services in Android

In this article, we are going to generate backup of our application by using Google backup services of Android.
Submitted by Manu Jemini, on February 06, 2018

First of all, we need to set two strings that clarify the preferences and backup key which are following:

    String file_name_for_setting_preferences = "ourpreferences";
    String preferences_backup_key = "bkup";

After that, we create a onCreate() method and use class SharedPreferencesBackupHelper to create an object and pass this as current context and our preferences string then call addHelper() method and pass backupkey and SharedPreferencesBackupHelper class object.

For backup key:

For backup key, you just need to go on the official site of android and register your app on google backup services. The URL for registration on official site is:

After entering your app package name you are eligible for registering on google backup services. After further process google backup services provide you a backup key generate backup of your application data, which you can use in your Android Manifest file as backup key.

Note: In below Android Manifest file, first you need to copy your google backup key and paste it here in android:value="Your key from google services" as android value.

After this, you are all set to go with your google backup services.

1) Java file:

package com.example.hp.myapplication;


public class MainActivity extends BackupAgentHelper {
	String file_name_for_setting_preferences = "ourpreferences";
	String preferences_backup_key = "bkup";

	public void onCreate() {
		SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this,
		addHelper(preferences_backup_key, helper);

2) Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            android:value="Your key from google services" />



3) String.xml:

    <string name="app_name">My Application</string>

Here is the command to enable your data backup in Android after doing above things: adb shell bmgr enable true

Next (this) command will enable the auto backup facility and to disable it you need to type: adb shell bmgr enable false

After doing all of this, you are all set for backing up data on Google backup services.

Related Tutorials

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.