android_SDK2.2_samples之BackupRestore(一)

在讲解该sample之前需要和大家聊聊这个东东。我们看下官方文档怎么解说这个。

Android's backup service allows you to copy your persistent application data to a remote "cloud" storage, in order to provide a restore point for the application data and settings. If a user performs a factory reset 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 are not required to reproduce their previous data or application settings. This process is completely transparent to the user and does not affect the functionality or user experience in your application.

翻译就不用我来了吧,主要是说把我们应用程序的数据存储到云端服务器上面。OK,至于更详细的你们可以查看一下文档,我在这里还想提点,如果你文档是2.2的,你会发现一点,这个介绍的前面有个new的标签。哈哈,知道了吧,这就是2.2的一个新特性。很多面试的时候会问你个个版本有哪些新特性,你可以说2.2有这个。然后我们来看看官方教我们怎么用

To implement a backup agent, you must:

  1. Declare your backup agent in your manifest file with the android:backupAgent attribute.
  2. Define a backup agent by either:

    1. Extending BackupAgent

      The BackupAgent class provides the central interface with which your application communicates with the Backup Manager. If you extend this class directly, you must override onBackup() and onRestore() to handle the backup and restore operations for your data.

      Or

    2. Extending BackupAgentHelper

      The BackupAgentHelper class provides a convenient wrapper around the BackupAgent class, which minimizes the amount of code you need to write. In your BackupAgentHelper, you must use one or more "helper" objects, which automatically backup and restore certain types of data, so that you do not need to implement onBackup() and onRestore().

      Android currently provides backup helpers that will backup and restore complete files from SharedPreferences and internal storage.

用法很简单。第一个就是要在AndroidManifest.xml有这个android:backupAgent这个属性。看看BackupRestore的这个文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.backuprestore"
    android:versionCode="1"
    android:versionName="1.0">

    <!-- The backup/restore mechanism was introduced in API version 8 -->
    <uses-sdk android:minSdkVersion="8"/>

    <application android:label="Backup/Restore"
        android:backupAgent="ExampleAgent">

      <activity android:name="BackupRestoreActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>
看到红色的部分了么?这既是第一步。呵呵,so easy。
然后就是扩展(继承)BackupAgent 和BackupAgentHelper 。之后在我们程序中使用这些扩展类。至于详细的,看我后面的教程。今天只是稍微了解一下这个东西,给你们掉下口味。哈哈


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值