Skip to content

Commit 753e560

Browse files
scottamainAndroid (Google) Code Review
authored andcommitted
Merge "docs: update backup dev guide with Android Backup Service registration info" into froyo
2 parents 17ae646 + 9643849 commit 753e560

File tree

1 file changed

+92
-21
lines changed

1 file changed

+92
-21
lines changed

docs/html/guide/topics/data/backup.jd

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ page.title=Data Backup
1515
<h2>In this document</h2>
1616
<ol>
1717
<li><a href="#Basics">The Basics</a></li>
18+
<li><a href="#BackupManifest">Declaring the Backup Agent in Your Manifest</a></li>
19+
<li><a href="#BackupKey">Registering for Android Backup Service</a></li>
1820
<li><a href="#BackupAgent">Extending BackupAgent</a>
1921
<ol>
2022
<li><a href="#RequiredMethods">Required Methods</a></li>
@@ -45,48 +47,74 @@ page.title=Data Backup
4547
</div>
4648

4749
<p>Android's {@link android.app.backup backup} service allows you to copy your persistent
48-
application data to a remote "cloud" storage, in order to provide a restore point for the
50+
application data to remote "cloud" storage, in order to provide a restore point for the
4951
application data and settings. If a user performs a factory reset or converts to a new
5052
Android-powered device, the system automatically restores your backup data when the application
51-
is re-installed. This way, your users are not required to reproduce their previous data or
53+
is re-installed. This way, your users don't need to reproduce their previous data or
5254
application settings. This process is completely transparent to the user and does not affect the
5355
functionality or user experience in your application.</p>
5456

55-
<p>Android-powered devices that support the backup service provide a cloud storage area that
56-
saves your backup data and a backup transport that delivers your data to
57-
the storage area and back to the device. During a backup
58-
operation, Android's Backup Manager requests backup data from your application, then delivers it to
59-
the cloud storage using the backup transport. During a restore operation, the Backup Manager
60-
retrieves the backup data from the backup transport and returns it to your application
61-
so it can restore the data to the device. The backup service is <em>not</em> designed for data
62-
synchronization (you do not have access the backup data, except during a restore operation on the
63-
device).</p>
64-
65-
<p>The cloud storage used for backup won't necessarily be the same on all Android-powered devices.
66-
The cloud storage and backup transport may differ between devices and service providers.
67-
Where the backup data is stored is transparent to your application, but you are assured that your
68-
application data cannot be read by other applications.</p>
57+
<p>During a backup operation (which your application can request), Android's Backup Manager ({@link
58+
android.app.backup.BackupManager}) queries your application for backup data, then hands it to
59+
a backup transport, which then delivers the data to the cloud storage. During a
60+
restore operation, the Backup Manager retrieves the backup data from the backup transport and
61+
returns it to your application so your application can restore the data to the device. It's
62+
possible for your application to request a restore, but that shouldn't be necessary&mdash;Android
63+
automatically performs a restore operation when your application is installed and there exists
64+
backup data associated with the user. The primary scenario in which backup data is restored is when
65+
a user resets their device or upgrades to a new device and their previously installed
66+
applications are re-installed.</p>
67+
68+
<p class="note"><strong>Note:</strong> The backup service is <em>not</em> designed for
69+
synchronizing application data with other clients or saving data that you'd like to access during
70+
the normal application lifecycle. You cannot read or write backup data on demand and cannot access
71+
it in any way other than through the APIs provided by the Backup Manager.</p>
72+
73+
<p>The backup transport is the client-side component of Android's backup framework, which is
74+
customizable by
75+
the device manufacturer and service provider. The backup transport may differ from device to device
76+
and which backup transport is available on any given device is transparent to your application. The
77+
Backup Manager APIs isolate your application from the actual backup transport available on a given
78+
device&mdash;your application communicates with the Backup Manager through a fixed set of APIs,
79+
regardless of the underlying transport.</p>
80+
81+
<p>Data backup is <em>not</em> guaranteed to be available on all Android-powered
82+
devices. However, your application is not adversely affected in the event
83+
that a device does not provide a backup transport. If you believe that users will benefit from data
84+
backup in your application, then you can implement it as described in this document, test it, then
85+
publish your application without any concern about which devices actually perform backup. When your
86+
application runs on a device that does not provide a backup transport, your application operates
87+
normally, but will not receive callbacks from the Backup Manager to backup data.</p>
88+
89+
<p>Although you cannot know what the current transport is, you are always assured that your
90+
backup data cannot be read by other applications on the device. Only the Backup Manager and backup
91+
transport have access to the data you provide during a backup operation.</p>
6992

7093
<p class="caution"><strong>Caution:</strong> Because the cloud storage and transport service can
7194
differ from device to device, Android makes no guarantees about the security of your data while
72-
using backup. You should be cautious about using backup to store sensitive data, such as usernames
73-
and passwords.</p>
95+
using backup. You should always be cautious about using backup to store sensitive data, such as
96+
usernames and passwords.</p>
7497

7598

7699
<h2 id="Basics">The Basics</h2>
77100

78101
<p>To backup your application data, you need to implement a backup agent. Your backup
79102
agent is called by the Backup Manager to provide the data you want to back up. It is also called
80103
to restore your backup data when the application is re-installed. The Backup Manager handles all
81-
your data transactions with the cloud storage and your backup agent handles all your data
82-
transactions on the device.</p>
104+
your data transactions with the cloud storage (using the backup transport) and your backup agent
105+
handles all your data transactions on the device.</p>
83106

84107
<p>To implement a backup agent, you must:</p>
85108

86109
<ol>
87110
<li>Declare your backup agent in your manifest file with the <a
88111
href="{@docRoot}guide/topics/manifest/application-element.html#agent">{@code
89112
android:backupAgent}</a> attribute.</li>
113+
<li>Register your application with a backup service. Google offers <a
114+
href="http://code.google.com/android/backup/index.html">Android Backup Service</a> as a backup
115+
service for most Android-powered devices, which requires that you register your application in
116+
order for it to work. Any other backup services available might also require you to register
117+
in order to store your data on their servers.</li>
90118
<li>Define a backup agent by either:</p>
91119
<ol type="a">
92120
<li><a href="#backupAgent">Extending BackupAgent</a>
@@ -118,7 +146,6 @@ href="{@docRoot}guide/topics/data/data-storage.html#filesInternal">internal stor
118146

119147

120148

121-
122149
<h2 id="BackupManifest">Declaring the Backup Agent in Your Manifest</h2>
123150

124151
<p>This is the easiest step, so once you've decided on the class name for your backup agent, declare
@@ -160,6 +187,50 @@ remaining compatible with older devices.</p>
160187

161188

162189

190+
<h2 id="BackupKey">Registering for Android Backup Service</h2>
191+
192+
<p>Google provides a backup transport with <a
193+
href="http://code.google.com/android/backup/index.html">Android Backup Service</a> for most
194+
Android-powered devices running Android 2.2 or greater.</p>
195+
196+
<p>In order for you application to perform backup using Android Backup Service, you must
197+
register your application with the service to receive a Backup Service Key, then
198+
declare the Backup Service Key in your Android manifest.</p>
199+
200+
<p>To get your Backup Service Key, <a
201+
href="http://code.google.com/android/backup/signup.html">register for Android Backup Service</a>.
202+
When you register, you will be provided a Backup Service Key and the appropriate {@code
203+
&lt;meta-data&gt;} XML code for your Android manifest file, which you must include as a child of the
204+
{@code &lt;application&gt;} element. For example:</p>
205+
206+
<pre>
207+
&lt;application android:label="MyApplication"
208+
android:backupAgent="MyBackupAgent"&gt;
209+
...
210+
&lt;meta-data android:name="com.google.android.backup.api_key"
211+
android:value="AEdPqrEAAAAIDaYEVgU6DJnyJdBmU7KLH3kszDXLv_4DIsEIyQ" /&gt;
212+
&lt;/application&gt;
213+
</pre>
214+
215+
<p>The <code>android:name</code> must be <code>"com.google.android.backup.api_key"</code> and
216+
the <code>android:value</code> must be the Backup Service Key received from the Android Backup
217+
Service registration.</p>
218+
219+
<p>If you have multiple applications, you must register each one, using the respective package
220+
name.</p>
221+
222+
<p class="note"><strong>Note:</strong> The backup transport provided by Android Backup Service is
223+
not guaranteed to be available
224+
on all Android-powered devices that support backup. Some devices might support backup
225+
using a different transport, some devices might not support backup at all, and there is no way for
226+
your application to know what transport is used on the device. However, if you implement backup for
227+
your application, you should always include a Backup Service Key for Android Backup Service so
228+
your application can perform backup when the device uses the Android Backup Service transport. If
229+
the device does not use Android Backup Service, then the {@code &lt;meta-data&gt;} element with the
230+
Backup Service Key is ignored.</p>
231+
232+
233+
163234

164235
<h2 id="BackupAgent">Extending BackupAgent</h2>
165236

0 commit comments

Comments
 (0)