Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:20:00+00:00 2026-06-12T11:20:00+00:00

I’m trying to implement Data Backup into my application. I build Android 2.2 project,

  • 0

I’m trying to implement Data Backup into my application. I build Android 2.2 project, and run in Galaxy s2 4.0.3.

I try to use: BackupManagerTest to save preferences to the cloud

This is my code :

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.amdroid.backuptest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:backupAgent="net.amdroid.backuptest.MyBackupAgent"
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".BackupManagerTestActivity"
            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="AEdPqrEAAAAI7_yf1xqlpltWZPZiKMHVlDgn3nMfgotjUweSUg" />
    </application>

</manifest>

MyBackupAgent.java

public class MyBackupAgent extends BackupAgentHelper {
    // The names of the SharedPreferences groups that the application maintains.  These
    // are the same strings that are passed to getSharedPreferences(String, int).
    static final String PREFS_TEST = "testprefs"; 

    // An arbitrary string used within the BackupAgentHelper implementation to
    // identify the SharedPreferenceBackupHelper's data.
    static final String MY_PREFS_BACKUP_KEY = "myprefs"; 

    // Simply allocate a helper and install it
    @Override
    public void onCreate() {
        SharedPreferencesBackupHelper helper =
                new SharedPreferencesBackupHelper(this, PREFS_TEST);
        addHelper(MY_PREFS_BACKUP_KEY, helper);
        Log.d("Test", "Adding backupagent...");
    }
}

My Activity

public class BackupManagerTestActivity extends Activity {

    private SharedPreferences prefs;
    private Editor edit;
    private BackupManager backupManager;
    private EditText text;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        backupManager = new BackupManager(getBaseContext());
        prefs = getSharedPreferences(MyBackupAgent.PREFS_TEST, Context.MODE_PRIVATE);
        edit = prefs.edit();

        text = (EditText) findViewById(R.id.editName);
        String nome = prefs.getString("KEY_NAME", "");
        text.setText(nome);

        Button button = (Button) findViewById(R.id.buttonSave);
        button.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                edit.putString("KEY_NAME", text.getText().toString());
                edit.commit();
                Log.d("Test", "Calling backup...");
                backupManager.dataChanged();
            }
        });
    }
}

So MyBackupAgent never called. I don’t know the reason.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:20:01+00:00Added an answer on June 12, 2026 at 11:20 am

    When you call backupManager.dataChanged(), it merely schedules your app for backup. It does not mean your backup helper is called right away.

    From http://developer.android.com/guide/topics/data/backup.html:

    You can request a backup operation at any time by calling dataChanged(). This method notifies the Backup Manager that you’d like to backup your data using your backup agent. The Backup Manager then calls your backup agent’s onBackup() method at an opportune time in the future. Typically, you should request a backup each time your data changes (such as when the user changes an application preference that you’d like to back up). If you call dataChanged() several times consecutively, before the Backup Manager requests a backup from your agent, your agent still receives just one call to onBackup().

    Note: While developing your application, you can request a backup and initiate an immediate backup operation with the bmgr tool.

    Instructions for the bmgr tool can be found at:
    http://developer.android.com/tools/help/bmgr.html

    To force all pending backup operations to run immediately, use:

    adb shell bmgr run
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.