Note that there are some explanatory texts on larger screens.

plurals
  1. POBackwards-compatible BackupAgent
    text
    copied!<p>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).</p> <p>The docs state:</p> <blockquote> <p>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.</p> </blockquote> <p>I indeed build against the level 8 <code>targetSdkVersion</code> with level 3 <code>minSdkVersion</code> 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.</p> <p>Here is the problem: since we don't make actual calls to the <code>BackupHelper</code> class ourselves, we can't check upfront if the class indeed exists. (As is explained in the Android Backwards Compatibility documentation with a <code>checkAvailable()</code> method.) The class will therefore be instantiated and cast to a <code>BackupAgent</code>. But since we use reflection, it doesn't actually override BackupAgent and an exception occurs at runtime when the backup is requested:</p> <pre><code>java.lang.RuntimeException: Unable to create BackupAgent org.transdroid.service.BackupAgent: java.lang.ClassCastException: org.transdroid.service.BackupAgent </code></pre> <p>Here is my approach to a backwards compatible <code>BackupAgent</code>: <a href="http://code.google.com/p/transdroid/source/browse/#svn/trunk/src/org/transdroid/service" rel="nofollow noreferrer">http://code.google.com/p/transdroid/source/browse/#svn/trunk/src/org/transdroid/service</a> where the BackupAgent.java is the 'regular' BackupAgentHelper-extending class and BackupAgentHelperWrapper is the reflection-based wrapper class.</p> <p>Anyone successfull in implementing a <code>BackupAgent</code> with backwards compatibility?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload