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

  • Home
  • SEARCH
  • 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 3271900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:46:23+00:00 2026-05-17T18:46:23+00:00

I am looking into using the new Backup API that available since Android 2.2,

  • 0

I am looking into using the new Backup API that available since Android 2.2, but need to maintain backwards compatibility (to 1.5 to be exact).

The docs state:

The backup service and the APIs you must use are available only on devices running API Level 8 (Android 2.2) or greater, so you should also set your android:minSdkVersion attribute to “8”. However, if you implement proper backward compatibility in your application, you can support this feature for devices running API Level 8 or greater, while remaining compatible with older devices.

I indeed build against the level 8 targetSdkVersion with level 3 minSdkVersion and try to use a wrapper class (with reflection) to overcome the problem that the application will not run if you implement a class that extends an nonexisting class.

Here is the problem: since we don’t make actual calls to the BackupHelper class ourselves, we can’t check upfront if the class indeed exists. (As is explained in the Android Backwards Compatibility documentation with a checkAvailable() method.) The class will therefore be instantiated and cast to a BackupAgent. But since we use reflection, it doesn’t actually override BackupAgent and an exception occurs at runtime when the backup is requested:

java.lang.RuntimeException: Unable to create BackupAgent org.transdroid.service.BackupAgent: java.lang.ClassCastException: org.transdroid.service.BackupAgent

Here is my approach to a backwards compatible BackupAgent: http://code.google.com/p/transdroid/source/browse/#svn/trunk/src/org/transdroid/service where the BackupAgent.java is the ‘regular’ BackupAgentHelper-extending class and BackupAgentHelperWrapper is the reflection-based wrapper class.

Anyone successfull in implementing a BackupAgent with backwards compatibility?

  • 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-05-17T18:46:23+00:00Added an answer on May 17, 2026 at 6:46 pm

    I don’t see why you run into this problem.

    I have the same issue: I want to support backup with a app that supports also 1.5 (API 3).

    There is no problem in creating my BackupAgentHelper class, since that class is never called from my own code, but from the BackupManager i.e. the system itself. Therefore I don’t need to wrap it, and I don’t see why you should be doing that:

     public class MyBackupAgentHelper extends BackupAgentHelper {
     @override onCreate()
     { 
           \\do something usefull
     }
    

    However, you do want to get a backup running, to do that you need to call on BackupManager.dataChanged() whenever your data changes and you want to inform the system to backup it (using your BackupAgent or BackupAgentHelper).

    You do need to wrap that class, since you call it from you application code.

    
    public class WrapBackupManager {
    private BackupManager wrappedInstance;
    
    static 
    {
        try
        {
            Class.forName("android.app.backup.BackupManager");
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }
    public static void checkAvailable() {}
    
    public void dataChanged()
    {
        wrappedInstance.dataChanged();
    }
    
    public WrapBackupManager(Context context)
    {
        wrappedInstance = new BackupManager(context);
    }
    
    }
    

    You then call it from your code when you change a preference or save some data.
    Some code from my app:

    
    private static Boolean backupManagerAvailable = null;
    
        private static void postCommitAction() {
    
    
            if (backupManagerAvailable == null) {
                try {
                    WrapBackupManager.checkAvailable();
                    backupManagerAvailable = true;
                } catch (Throwable t) {
                    backupManagerAvailable = false;
                }
            }
    
            if (backupManagerAvailable == true) {
                Log.d("Fretter", "Backup Manager available, using it now.");
                WrapBackupManager wrapBackupManager = new WrapBackupManager(
                        FretterApplication.getApplication());
                wrapBackupManager.dataChanged();
            } else {
                Log.d("Fretter", "Backup Manager not available, not using it now.");
            }
    

    So, hopefully this works for you!

    (If you call adb shell bmgr run every time you want to emulate the actual system initiated backupprocess it should properly backup and restore when you reinstall the app.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.