blob: a24dba8fe50fe45f1b6513cf290a2c59c16b0394 [file] [log] [blame]
Scott Mainadaf5a72011-02-16 15:52:38 -08001page.title=Optimizing Apps for Android 3.0
2@jd:body
3
4<div id="qv-wrapper">
5<div id="qv">
6<h2>In this document</h2>
7<ol>
Scott Mainae7067f2011-02-24 11:16:30 -08008<li><a href="#Setup">Setting Up Your SDK with Android 3.0</a></li>
9<li><a href="#Optimizing">Optimizing Your App for Tablets</a></li>
10<li><a href="#Upgrading">Upgrading or Developing a New App for Tablets</a></li>
11<li><a href="#ManagingAppDist">Managing App Distribution Based on Screen Configuration</a>
12 <ol>
13 <li><a href="#FilteringTabletApps">Filtering a tablet app from mobile devices</a></li>
14 <li><a href="#FilteringMobileApps">Filtering a mobile device app from tablets</a></li>
15 </ol>
16</li>
17<li><a href="#Issues">Other Issues</a>
18 <ol>
19 <li><a href="#Landscape">Adding support for landscape screens</a></li>
20 <li><a href="#Telephony">Using telephony or other variable features</a></li>
21 </ol>
22</li>
Scott Mainadaf5a72011-02-16 15:52:38 -080023</ol>
24
Scott Main28fb09e2011-05-23 17:27:17 -070025<h2>See also</h2>
26
27<ol>
28 <li><a
29href="{@docRoot}sdk/compatibility-library.html">Compatibility Library</a></li>
30 <li><a href="http://code.google.com/p/iosched/">Google I/O App source code</a></li>
31</ol>
32
Scott Mainadaf5a72011-02-16 15:52:38 -080033</div>
34</div>
35
Scott Mainae7067f2011-02-24 11:16:30 -080036<p>Android 3.0 introduces several features that allow
Scott Mainadaf5a72011-02-16 15:52:38 -080037you to enhance your user's experience on tablets and similar devices. Any application you've already
38published is compatible with devices running Android 3.0, by default, because Android applications
Scott Mainae7067f2011-02-24 11:16:30 -080039are forward-compatible. However, new tablet devices running Android 3.0 are now available to the
40public and provide users a new Android experience on a larger screen, so you should make sure
41your application looks and works great on the new platform and new device form-factors.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -080042
43<p>This document shows how you can optimize your existing application for Android 3.0 and
44maintain compatibility with older versions or upgrade your application completely with new APIs.</p>
45
46
47<p><b>To get started:</b></p>
48
49<ol>
Scott Mainae7067f2011-02-24 11:16:30 -080050 <li><a href="#Setup">Set up your SDK with Android 3.0</a>.
51 <p>Install the Android 3.0 platform, new tools, and set up a new AVD.</p></li>
52 <li>Choose to either optimize or upgrade:
Scott Mainadaf5a72011-02-16 15:52:38 -080053 <ol type="a">
Scott Mainae7067f2011-02-24 11:16:30 -080054 <li><a href="#Optimizing">Optimize your app for tablets and similar devices</a>.
55 <p>Read this section if you have an existing application and want to
56maintain compatibility with older versions of Android. All you need to do is update your
57manifest file to declare support for Android 3.0, test your application on the new platform, and
58add extra resources to support extra large screens, as appropriate.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -080059 </li>
Scott Mainae7067f2011-02-24 11:16:30 -080060 <li><a href="#Upgrading">Upgrade or develop a new app for tablets and similar devices</a>.
61 <p>Read this section if you want to upgrade your application to use APIs introduced in
62Android 3.0 or create a new application targeted to tablets and similar devices. Compared to
63upgrading to previous versions of Android, there's nothing different about upgrading to Android 3.0.
64This section introduces some of the key features and APIs you should use to make an
65application that's fully enhanced for tablets.</p></li>
Scott Mainadaf5a72011-02-16 15:52:38 -080066 </ol>
67 </li>
Scott Mainae7067f2011-02-24 11:16:30 -080068 <li>Consider whether you need to <a href="#ManagingAppDist">manage the distribution of your
69application based on screen configuration</a>.</li>
70 <li>Then review some <a href="#Issue">other issues</a> you might encounter when developing
71for tablets and similar devices.</li>
Scott Mainadaf5a72011-02-16 15:52:38 -080072</ol>
73
74
75<h2 id="Setup">Set Up Your SDK with Android 3.0</h2>
76
77<p>To start testing and developing your application on Android 3.0, set up your existing Android
78SDK with the new platform:</p>
79
80<p>(If you don't have an existing Android SDK, <a href="{@docRoot}sdk/index.html">download the
81SDK starter package now</a>.)</p>
82
83<ol>
84 <li><a href="{@docRoot}sdk/adding-components.html#launching">Launch the Android SDK and AVD
85Manager</a> and install the following:
86 <ul>
87 <li>SDK Platform Android 3.0</li>
88 <li>Android SDK Tools, revision 10</li>
89 <li>Android SDK Platform-tools, revision 3</li>
90 <li>Documentation for Android SDK, API 11</li>
91 <li>Samples for SDK API 11</li>
92 </ul>
93 </li>
94 <li><a href="{@docRoot}guide/developing/other-ide.html#AVD">Create an AVD</a> for a tablet-type
95device:
96 <p>Set the target to "Android 3.0" and the skin to "WXGA" (the default skin).</p></li>
97</ol>
98
Scott Mainae7067f2011-02-24 11:16:30 -080099<p>The best way to test your application on Android 3.0 is to use real hardware running Android 3.0,
100such as the <a href="http://www.motorola.com/staticfiles/Consumers/XOOM/index.html">Motorola
101Xoom</a>. Of course, you can also use the Android emulator on your development machine, but because
102the Android emulator must simulate the ARM instruction set on your computer and the WXGA screen is
103significantly larger than a typical virtual device, emulator performance is much slower than a real
104device.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800105
106<h3>About emulator performance</h3>
107
Scott Mainae7067f2011-02-24 11:16:30 -0800108<p>Initializing the emulator can be slow and can take several minutes, depending on
Scott Mainadaf5a72011-02-16 15:52:38 -0800109your hardware. When the emulator is booting, there is limited user feedback, so please be patient
110and wait until you see the home screen (or lock screen) appear. </p>
111
112<p>However, you don't need to boot the emulator each time you rebuild your
113application&mdash;typically you only need to boot at the start of a session and keep it running.
114Also see the tip below for information about using a snapshot to drastically reduce startup time
115after the first initialization. </p>
116
Scott Mainae7067f2011-02-24 11:16:30 -0800117<p>General performance in the emulator is also slow. We're working hard to resolve the performance
118issues and it will improve in future tools releases. If you don't yet have a real device running
119Android 3.0, the emulator is still best way to evaluate your application's appearance and
120functionality on Android 3.0.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800121
122<p class="note"><strong>Tip:</strong> To improve the startup time for the emulator, enable snapshots
123for the AVD when you create it with the SDK and AVD Manager (there's a checkbox in the AVD creator
124to <strong>Enable</strong> snapshots). Then, start the AVD from the AVD manager and check <b>Launch
125from snapshot</b> and <b>Save to snapshot</b>. This way, when you close the emulator, a snapshot of
126the AVD state is saved and used to quickly relaunch the AVD next time. However, when you choose to
127save a snapshot, the emulator will be slow to close, so you might want to disable <b>Save to
128snapshot</b> after you've acquired an initial snapshot (after you close the AVD for the first
129time).</p>
130
131
132
Scott Mainae7067f2011-02-24 11:16:30 -0800133<h2 id="Optimizing">Optimizing Your App for Tablets</h2>
Scott Mainadaf5a72011-02-16 15:52:38 -0800134
135<p>If you've already developed an application for an earlier version of Android, there are a few
136things you can do to optimize it for a tablet-style experience on Android 3.0 without changing the
137minimum version required (you don't need to change your manifest's <a
138href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
139android:minSdkVersion}</a>).</p>
140
141<p class="note"><strong>Note:</strong> All Android applications are forward-compatible, so
142there's nothing you <em>have to</em> do&mdash;if your application is a good citizen of the Android
143APIs, your app should work fine on devices running Android 3.0. However, in order to provide users
144a better experience when using your app on an Android 3.0 tablet or similar-size device, you
145should update your application to inherit the new system theme and provide some optimizations for
146larger screens.</p>
147
148<p>Here are a few things you can do to optimize your application for devices running Android
1493.0:</p>
150
151<ol>
152 <li><b>Test your current application on Android 3.0</b>
153 <ol>
154 <li>Build your application as-is and install it on your Android 3.0 AVD (created above during
155<a href="#Setup">setup</a>).</li>
156 <li>Perform your usual tests to be sure everything works and looks as expected.</li>
157 </ol>
158 </li>
159
160 <li><b>Apply the new "holographic" theme to your application</b>
161 <ol>
162 <li>Open your manifest file and update the <a
163href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">{@code &lt;uses-sdk&gt;}</a> element to
164set <a
165href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
166android:targetSdkVersion}</a> to {@code "11"}. For example:
167<pre>
168&lt;manifest ... >
169 &lt;uses-sdk android:minSdkVersion="4"
170 android:targetSdkVersion="11" /&gt;
171 &lt;application ... >
172 ...
173 &lt;application>
174&lt;/manifest>
175</pre>
176 <p>By targeting the Android 3.0 platform, the system automatically applies the holographic theme
177to each activity when your application runs on an Android 3.0 device. The holographic theme
Scott Mainae7067f2011-02-24 11:16:30 -0800178provides a new design for widgets, such as buttons and text boxes, and new styles for other
179visual elements. This is the standard theme for applications built for Android 3.0, so your
180application will look and feel consistent with the system and other applications when it is
181enabled.</p>
182 <p>Additionally, when an activity uses the holographic theme, the system enables the <a
Scott Main28fb09e2011-05-23 17:27:17 -0700183href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar</a> for the activity and removes the
184Options Menu button in the system bar. The Action Bar
Scott Mainae7067f2011-02-24 11:16:30 -0800185replaces the traditional title bar at the top of the activity window and provides the user access to
186the activity's Options Menu.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800187 </li>
Scott Mainae7067f2011-02-24 11:16:30 -0800188 <li>Build your application against the same version of the Android platform you have been
189using previously (such as the version declared in your <a
190href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>),
191but install it on the Android 3.0 AVD. (You should not build against Android 3.0 unless you are
192using new APIs.) Repeat your tests to be sure that your user interface works well with the
193holographic theme.
Scott Mainadaf5a72011-02-16 15:52:38 -0800194 <p class="note"><strong>Note:</strong> If you have applied other themes directly to your
195activities, they will override the inherited holographic theme. To resolve this, you can use
Scott Mainae7067f2011-02-24 11:16:30 -0800196the <a href="{@docRoot}guide/topics/resources/providing-resources.html#VersionQualifier">platform
Scott Mainadaf5a72011-02-16 15:52:38 -0800197version qualifier</a> to provide an alternative theme for Android 3.0 devices that's based on the
198holographic theme. For more information, read how to <a
199href="{@docRoot}guide/topics/ui/themes.html#SelectATheme">select a theme based on platform
200version</a>.</p>
201 </ol>
202 </li>
203
204 <li><b>Supply alternative layout resources for xlarge screens</b>
205 <p>By providing <a
206href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">alternative
207resources</a> when running on extra large screens (using the <code>xlarge</code> resource
208qualifier), you can improve the user experience of your application on tablet-type devices without
209using new APIs.</p>
210 <p>For example, here are some things to consider when creating a new layout for extra large
211screens:</p>
212 <ul>
213 <li>Landscape layout: The "normal" orientation for tablet-type devices is usually landscape
214(wide), so you should be sure that your activities offer a layout that's optimized for a wide
215viewing area. <p>You can specify landscape resources with the <code>land</code> resource
216qualifier, but if you want alternative resources for an extra large landscape screen, you
Scott Mainae7067f2011-02-24 11:16:30 -0800217should use both the <code>xlarge</code> and <code>land</code> qualifiers. For example, {@code
Scott Mainadaf5a72011-02-16 15:52:38 -0800218res/layout-xlarge-land/}. The order of the qualifier names is important; see <a
219href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">
220Providing Alternative Resources</a> for more information.</p></li>
Scott Mainae7067f2011-02-24 11:16:30 -0800221 <li>Button position and size: Consider whether the position and size of the most common
222buttons in your UI make them easily accessible while holding a tablet with two hands. In some
223cases, you might need to resize buttons, especially if they use {@code "wrap_content"}
224as the width value. To enlarge the buttons, if necessary, you should either: add
225extra padding to the button; specify dimension values with {@code dp} units; or use {@code
226android:layout_weight} when the button is in a <a
227href="{@docRoot}guide/topics/ui/layout-objects.html#linearlayout">linear layout</a>. Use your
228best judgment of proportions for each screen size&mdash;you don't want the buttons to be too big,
229either.</li>
Scott Mainadaf5a72011-02-16 15:52:38 -0800230 <li>Font sizes: Be sure your application uses {@code sp} units when setting font
Scott Mainae7067f2011-02-24 11:16:30 -0800231sizes. This alone should ensure a readable experience on tablet-style devices, because it is a
232scale-independent pixel unit, which will resize as appropriate for the current screen configuration.
233In some cases, however, you still might want to consider larger font sizes for <code>xlarge</code>
234configurations.</li>
Scott Mainadaf5a72011-02-16 15:52:38 -0800235 </ul>
236 <p>In general, always be sure that your application follows the <a
237href="{@docRoot}guide/practices/screens_support.html#screen-independence">Best Practices
238for Screen Independence</a>.</p>
239 </li>
240</ol>
241
242
243
244
Scott Mainae7067f2011-02-24 11:16:30 -0800245<h2 id="Upgrading">Upgrading or Developing a New App for Tablets</h2>
246
247<div class="sidebox-wrapper">
248<div class="sidebox">
Scott Main28fb09e2011-05-23 17:27:17 -0700249 <h3>Use the Compatibility Library to remain backward-compatible</h3>
Scott Mainae7067f2011-02-24 11:16:30 -0800250<p>It is possible for you to upgrade your application with some new
251APIs <em>and</em> remain compatible with older versions of Android. Usually, this requires that you
252use techniques such as reflection to check for the availability of certain APIs at runtime. However,
253to help you add features from Android 3.0 without requiring you to change your <a
254href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>
Scott Main28fb09e2011-05-23 17:27:17 -0700255or build target, we're providing a static library called the <a
256href="{@docRoot}sdk/compatibility-library.html">Compatibility Library</a>
Scott Mainae7067f2011-02-24 11:16:30 -0800257(downloadable from the AVD and SDK Manager).</p>
258<p>This library includes APIs for <a
259href="{@docRoot}guide/topics/fundamentals/fragments.html">fragments</a>, <a
260href="{@docRoot}guide/topics/fundamentals/loaders.html">loaders</a>, and some updated classes. By
261simply adding this library to your Android project, you can use these APIs in your application and
Scott Main28fb09e2011-05-23 17:27:17 -0700262remain compatible with Android 1.6. For information about how to get the library and start
263using it in your application, see the <a
264href="{@docRoot}sdk/compatibility-library.html">Compatibility Library</a> document.</p>
Scott Mainae7067f2011-02-24 11:16:30 -0800265</div>
266</div>
267
Scott Mainadaf5a72011-02-16 15:52:38 -0800268
269<p>If you want to develop an application that's fully enhanced for tablet-type devices running
270Android 3.0, then you need to use new APIs in Android 3.0. This section introduces some of
271the new features you should use.</p>
272
273
274<h3>Declare the minimum system version</h3>
275
Scott Mainae7067f2011-02-24 11:16:30 -0800276<p>The first thing to do when you upgrade or create a project for Android 3.0 is set your manifest's
277<a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code
278android:minSdkVersion}</a> to {@code "11"}. This declares that your application uses APIs available
279in Android 3.0 and greater, so it should not be available to devices running an older version of
280Android. For example:</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800281
282<pre>
283&lt;manifest ... >
284 &lt;uses-sdk android:minSdkVersion="11" /&gt;
285 &lt;application ... >
286 ...
287 &lt;application>
288&lt;/manifest>
289</pre>
Scott Mainae7067f2011-02-24 11:16:30 -0800290
291<p>Not only is this necessary in order to declare the minimum API level your application requires,
292but it enables the new holographic theme to each of your activities. The holographic theme is the
293standard theme for the Android 3.0 system and all applications designed for it. It includes new
294designs for the system widgets and overall appearance.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800295
296<p>Additionally, the holographic theme enables the Action Bar for each activity.</p>
297
298
299<h3>Use the Action Bar</h3>
300
301<p>The Action Bar is a widget for activities that replaces the traditional title bar at the top of
302the screen. By default, the Action Bar includes the application logo on the left side, followed by
Scott Mainae7067f2011-02-24 11:16:30 -0800303the activity title, and access to items from the Options Menu in a drop-down list on the right
304side.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800305
Scott Mainae7067f2011-02-24 11:16:30 -0800306<p>You can enable items from the Options Menu to appear directly in the Action Bar as
307"action items" by adding {@code showAsAction="ifRoom"} to specific menu items in your <a
Scott Mainadaf5a72011-02-16 15:52:38 -0800308href="{@docRoot}guide/topics/resources/menu-resource.html">menu resource</a>. You can also add
309navigation features to the Action Bar, such as tabs, and use the application icon to navigate to
Scott Mainae7067f2011-02-24 11:16:30 -0800310your application's "home" activity or to navigate "up" the application's activity hierarchy.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800311
312<p>For more information, read <a href="{@docRoot}guide/topics/ui/actionbar.html">Using the
313Action Bar</a>.</p>
314
315
316
317<h3>Divide your activities into fragments</h3>
318
Scott Mainae7067f2011-02-24 11:16:30 -0800319<p>A fragment represents a behavior or a portion of user interface in an activity. You can think of
320a fragment as a modular section of an activity, which has its own lifecycle, receives its own input
321events, and which you can add or remove while the activity is running. Fragments are an optional
322component for your activities that allow you to build a multi-pane UI and reuse them in multiple
323activities. If you're building an application for tablets, we recommend that you use fragments to
324create activities that offer a more dynamic and flexible user interface.</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800325
326<p>For example, a news application can use one fragment to show a list of articles on the left and
327another fragment to display an article on the right&mdash;both fragments appear in one activity,
328side by side, and each fragment has its own set of lifecycle callback methods and handles its own
329input events. Thus, instead of using one activity to select an article and another activity to
330read the article, the user can select an article and read it all within the same activity.</p>
331
332<p>For more information, read the <a
333href="{@docRoot}guide/topics/fundamentals/fragments.html">Fragments</a> document.</p>
334
335
336<h3>Use new animation APIs for transitions</h3>
337
Scott Mainae7067f2011-02-24 11:16:30 -0800338<p>An all-new animation framework allows you to animate arbitrary properties of any object
339(such as a View, Drawable, Fragment, or anything else). You can define several animation aspects
Scott Mainadaf5a72011-02-16 15:52:38 -0800340(such as duration, repeat, interpolation, and more) for an object's int, float, and hexadecimal
341color values, by default. That is, when an object has a property field for one of these types, you
342can change its value over time to affect an animation.</p>
343
344<p>The {@link android.view.View} class also provides new APIs that leverage the new animation
345framework, allowing you to easily apply 2D and 3D transformations to views in your activity layout.
346New transformations are made possible with a set of object properties that define the view's layout
347position, orientation, transparency and more.</p>
348
349<p>For more information, read the <a
350href="{@docRoot}guide/topics/graphics/animation.html">Property Animation</a> document.</p>
351
352
353<h3>Enable hardware acceleration</h3>
354
Scott Mainae7067f2011-02-24 11:16:30 -0800355<p>Android 3.0 adds a hardware-accelerated OpenGL renderer that gives a performance boost to most 2D
356graphics operations. You can enable hardware-accelerated rendering in your application by setting
357{@code android:hardwareAccelerated="true"} in your manifest's <a
Scott Mainadaf5a72011-02-16 15:52:38 -0800358href="{@docRoot}guide/topics/manifest/application-element.html">{@code &lt;application&gt;}</a>
359element or for individual <a href="{@docRoot}guide/topics/manifest/activity-element.html">{@code
360&lt;activity&gt;}</a> elements. Hardware acceleration results in smoother animations, smoother
361scrolling, and overall better performance and response to user interaction. When enabled, be sure
362that you thoroughly test your application on a device that supports hardware acceleration.</p>
363
364
365<h3>Enhance your app widgets</h3>
366
367<p>App widgets allow users to access information from your application directly from the Home
368screen and interact with ongoing services (such as preview their email and control music playback).
369Android 3.0 enhances these capabilities by enabling collections, created with widgets such as
370{@link android.widget.ListView}, {@link android.widget.GridView}, and the new {@link
371android.widget.StackView}. These widgets allow you to create more interactive app
372widgets, such as one with a scrolling list, and can automatically update their data through a {@link
373android.widget.RemoteViewsService}.</p>
374
375<p>Additionally, you should create a preview image of your app widget using the Widget Preview
376application (pre-installed in an Android 3.0 AVD) and reference it with the {@link
377android.appwidget.AppWidgetProviderInfo#previewImage android:previewImage} attribute, so that users
378can see what the app widget looks like before adding it to their Home screen.</p>
379
380
381<h3>Add other new features</h3>
382
383<p>Android 3.0 introduces many more APIs that you might find valuable for your
384application, such as drag and drop APIs, new Bluetooth APIs, a system-wide clipboard framework, a
385new graphics engine called Renderscript, and more.</p>
386
387<p>To learn more about the APIs mentioned above and more, see the <a
388href="{@docRoot}sdk/android-3.0.html">Android 3.0 Platform</a> document.</p>
389
390
Scott Mainadaf5a72011-02-16 15:52:38 -0800391<h3>Look at some samples</h3>
392
Scott Mainae7067f2011-02-24 11:16:30 -0800393<p>Many of the new features and APIs that are described above and in the <a
394href="{@docRoot}sdk/android-3.0.html#api">Android 3.0 Platform</a> document also have accompanying
395samples that allow you to preview the effects and can help you understand how to use them. To get
396the samples, download them from the SDK repository <a href="{@docRoot}sdk/adding-components.html"
397>using the Android SDK and AVD Manager</a>. After downloading the samples ("Samples for SDK API
39811"), you can find them in <code>&lt;sdk_root&gt;/samples/android-11/</code>. The following list
399provides links to the browsable source code for some of the samples:</p>
Scott Mainadaf5a72011-02-16 15:52:38 -0800400
401<ul>
402 <li><a href="{@docRoot}resources/samples/HoneycombGallery/index.html">Honeycomb Gallery</a>:
403Demonstrates many new APIs in Android 3.0, including fragments, the action bar, drag and drop, and
404animations.</li>
405 <li><a
406href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/index.html#Fragment">
407Fragments</a>: Various samples that demonstrate fragment layouts, back stack, restoring state, and
408more.</li>
409 <li><a
410href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/ActionBarMechanics.html"
411>Action Bar</a>: Samples that demonstrate various Action Bar features, such as tabs, logos, and
412action items.</li>
413 <li><a
Scott Main19aad292011-10-18 16:57:32 -0700414href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/content/ClipboardSample.html"
415>Clipboard</a>: An example of how to use the clipboard for copy and paste operations.</li>
Scott Mainadaf5a72011-02-16 15:52:38 -0800416 <li><a
417href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/DragAndDropDemo.html">
418Drag and Drop</a>: An example of how to perform drag and drop with new View events.</li>
419 <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/List15.html">
420Multi-choice List</a>: An example of how to provide multiple-choice selection for ListView and
421GridView.</li>
422 <li><a
423href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/app/LoaderThrottle.html">
424Content Loaders</a>: An example using new Loader APIs to asynchronously load data.</li>
425 <li><a
426href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/index.html">
427Property Animation</a>: Several samples using the new animation APIs to animate object
428properties.</li>
429 <li><a
Scott Main19aad292011-10-18 16:57:32 -0700430href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/view/SearchViewActionBar.html">
431Search View Widget</a>: Example using the new search widget in the Action Bar (as an
Scott Mainadaf5a72011-02-16 15:52:38 -0800432"action view").</li>
433 <li><a
Scott Main19aad292011-10-18 16:57:32 -0700434href="{@docRoot}resources/samples/RenderScript/index.html">Renderscript</a>: Contains several
Scott Mainadaf5a72011-02-16 15:52:38 -0800435different applications that demonstrate using renderscript APIs for computations and 3D
436graphics.</li>
437</ul>
438
Scott Mainae7067f2011-02-24 11:16:30 -0800439
440
441<h2 id="ManagingAppDist">Managing App Distribution Based on Screen Configuration</h2>
442
443<p>If your manifest file has either <a
444href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a>
445or <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
446android:targetSdkVersion}</a> set to {@code "4"} or higher, then the Android system will scale your
447application's layout and assets to fit the current device screen, whether the device screen is
448smaller or larger than the one for which you originally designed your application. As such, you
449should always test your application on real or <a
450href="{@docRoot}guide/developing/devices/index.html">virtual devices</a> with various screen sizes
451and densities.</p>
452
453<p>Although we recommend that you design your application to function properly on multiple
454configurations of screen size and density, you can instead choose to limit the distribution of your
455application to certain types of screens, such as only tablets or only mobile devices. To do so, you
456can add elements to your Android manifest file that enable filtering based on screen configuration
457by external services such as Android Market.</p>
458
459<p>However, before you decide to restrict your application to certain screen configurations, you
460should understand the techniques for <a
461href="{@docRoot}guide/practices/screens_support.html">supporting multiple screens</a> and employ
462them to the best of your ability. By supporting multiple screens, your application can be made
463available to the greatest number of users with different devices.</p>
464
465
466<h3 id="FilteringTabletApps">Filtering a tablet application from mobile devices</h3>
467
468<p>If the system scaling adversely affects your application UI when scaling your application down
469for smaller screens, you should add <a
470href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">alternative
471layouts</a> for smaller screens to adjust your layout. However, sometimes your layout still might
472not fit a smaller screen or you've explicitly designed your application only for tablets and other
473large devices. In this case, you can manage the availability of your application to smaller screens
474by using the <a href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code
475&lt;supports-screens>}</a> manifest element.</p>
476
477<p>For example, if you want your application to be available only to extra large
478screens, you can declare the element in your manifest like this:</p>
479
480<pre>
481&lt;manifest ... >
482 ...
483 &lt;supports-screens android:smallScreens="false"
484 android:normalScreens="false"
485 android:largeScreens="false"
486 android:xlargeScreens="true" /&gt;
487 &lt;application ... >
488 ...
489 &lt;application>
490&lt;/manifest>
491</pre>
492
493<p>External services such as Android Market read this manifest element and use it to ensure that
494your application is available only to devices with an extra large screen.</p>
495
496<p class="note"><strong>Note:</strong> If you use the <a
497href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code
498&lt;supports-screens>}</a> element for the reverse scenario (when your application is not compatible
499with <em>larger</em> screens) and set the larger screen size attributes to {@code "false"}, then
500external services such as Android Market <strong>do not</strong> apply filtering. Your application
501will still be available to larger screens, but when it runs, it will not fill the screen&mdash;the
502system will draw it in a "postage stamp" window that's the same relative size as the screen size
503that your application does support. If you want to prevent your application from being downloaded on
504larger screens, see the following section.</p>
505
506
507<h3 id="FilteringMobileApps">Filtering a mobile device application from tablets</h3>
508
509<p>Because Android automatically scales applications to fit larger screens, you shouldn't
510need to filter your application from larger screens. However, you might discover that your
511application can't scale up or perhaps you've decided to publish two versions of your application
512that each deliver different features for different screen configurations, so you don't want
513larger devices to download the version designed for smaller screens. In such a case, you can
514use the <a href="{@docRoot}guide/topics/manifest/compatible-screens-element.html">{@code
515&lt;compatible-screens>}</a> element to manage the distribution of your application based on the
516combination of screen size and density. External services such as
517Android Market uses this information to apply filtering to your application, so that only devices
518that have a screen configuration with which you declare compatibility can download your
519application.</p>
520
521<p>The <a href="{@docRoot}guide/topics/manifest/compatible-screens-element.html">{@code
522&lt;compatible-screens>}</a> element must contain one or more {@code &lt;screen&gt;} elements,
523which each specify a screen configuration with which your application is compatible, using both
524the {@code android:screenSize} and {@code android:screenDensity} attributes. Each {@code
525&lt;screen&gt;} element <strong>must include both attributes</strong> to specify an individual
526screen configuration&mdash;if either attribute is missing, then the element is invalid
527(external services such as Android Market will ignore it).</p>
528
529<p>For example, if your application is compatible with only small and normal screens, regardless
530of screen density, then you must specify eight different {@code &lt;screen&gt;} elements,
531because each screen size has four density configurations. You must declare each one of
532these; any combination of size and density that you do <em>not</em> specify is considered a screen
533configuration with which your application is <em>not</em> compatible. Here's what the manifest
534entry looks like if your application is compatible with only small and normal screens:</p>
535
536<pre>
537&lt;manifest ... >
538 ...
539 &lt;compatible-screens>
540 &lt;!-- all small size screens -->
541 &lt;screen android:screenSize="small" android:screenDensity="ldpi" />
542 &lt;screen android:screenSize="small" android:screenDensity="mdpi" />
543 &lt;screen android:screenSize="small" android:screenDensity="hdpi" />
544 &lt;screen android:screenSize="small" android:screenDensity="xhdpi" />
545 &lt;!-- all normal size screens -->
546 &lt;screen android:screenSize="normal" android:screenDensity="ldpi" />
547 &lt;screen android:screenSize="normal" android:screenDensity="mdpi" />
548 &lt;screen android:screenSize="normal" android:screenDensity="hdpi" />
549 &lt;screen android:screenSize="normal" android:screenDensity="xhdpi" />
550 &lt;/compatible-screens>
551 &lt;application ... >
552 ...
553 &lt;application>
554&lt;/manifest>
555</pre>
556
557<p class="note"><strong>Note:</strong> Although you can also use the <a
558href="{@docRoot}guide/topics/manifest/compatible-screens-element.html">{@code
559&lt;compatible-screens>}</a> element for the reverse scenario (when your application is not
560compatible with smaller screens), it's easier if you instead use the <a
561href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code
562&lt;supports-screens>}</a> as discussed in the previous section, because it doesn't require you
563to specify each screen density your application supports.</p>
564
565<p>Remember, you should strive to make your application available to as many devices as possible by
566applying all necessary techniques for <a
567href="{@docRoot}guide/practices/screens_support.html">supporting multiple screens</a>. You should
568then use the <a href="{@docRoot}guide/topics/manifest/compatible-screens-element.html">{@code
569&lt;compatible-screens>}</a> element to filter your application from certain devices only when you
570cannot offer compatibility on all screen configurations or you have decided to provide
571multiple versions of your application, each for a different set of screen configurations.</p>
572
573
574
575<h2 id="Issues">Other Issues</h2>
576
577<p>Whether you decide to optimize or upgrade your application for tablet-type devices, you
578should be aware that the functionality and availability of your application on new devices
579might be affected by the following issues:</p>
580
581<ul>
582 <li><a href="#Landscape">Tablets are often designed for use in the landscape orientation</a>
583 <p>Tablets and similar devices often have a screen that uses the landscape orientation
584by default. If your application assumes a portrait orientation or locks into portrait
585orientation, you should update your application to support landscape.</p></li>
586 <li><a href="#Telephony">Not all devices have telephony or other features</a>
587 <p>If your application declares the {@code "android.hardware.telephony"} feature in the manifest,
588then it will not be available to devices that do not offer telephony (such as tablets), based on
589Android Market filtering. If your application can function properly without telephony, you should
590update your application to gracefully disable the telephony features when not available on a
591device.</p></li>
592</ul>
593
594
595<h3 id="Landscape">Adding support for landscape screens</h3>
596
597<p>Although tablets can rotate to operate in any orientation, they are often designed for
598landscape orientation and that is how most users will use them. So, you should ensure that your
599application can function in landscape. Even if you want to avoid rotating the screen while your
600application is running, you should not assume that portrait is the device's default orientation. You
601should either ensure that your layout is usable in both portrait and landscape orientations or
602provide an <a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources"
603>alternative layout resource</a> for landscape orientation.</p>
604
605<p>If you believe your application or game provides its best experience when the screen is tall,
606consider that tablets and similar devices have a screen that's as tall or taller in landscape
607orientation than a phone in portrait orientation. With that in mind, you might be able to add a
608landscape design that adds padding or extra landscape scenery on the left and right sides, so
609the primary screen space still remains taller than it is wide.</p>
610
611<p>Ideally, your application should handle all orientation changes instead of locking into one
612orientation. When the user rotates the screen, the system restarts the current activity by calling
613{@link android.app.Activity#onDestroy onDestroy()} and {@link android.app.Activity#onCreate
614onCreate()}) in immediate succession. You should design your activity to account for these changes
615in the lifecycle, so the activity can save and restore its state. You can learn about the
616necessary lifecycle callback methods and how to save and restore the activity state in the <a
617href="{@docRoot}guide/topics/fundamentals/activities.html#Lifecycle">Activities</a>
618document. If your activity state is more complex and cannot retain it using the normal
619lifecycle callback methods, you can use alternative techniques described in <a
620href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime Changes</a>.</p>
621
622<p>In the worst-case scenario, however, you can avoid orientation changes by using the <a
623href="{@docRoot}guide/topics/manifest/activity-element.html#screen">{@code
624android:screenOrientation}</a> attribute in the <a
625href="{@docRoot}guide/topics/manifest/activity-element.html">{@code &lt;activity&gt;}</a>
626element. Instead of locking the orientation in landscape or portrait, however, you should
627specify a value of {@code "nosensor"}. This way, your activity uses whatever orientation the
628device specifies as its natural orientation and the screen will not rotate. You should still
629avoid using the <a
630href="{@docRoot}guide/topics/manifest/activity-element.html#screen">{@code
631android:screenOrientation}</a> attribute, but because it's sometimes necessary to lock the
632screen into one orientation, it's best if you do so in a way that uses the device's natural
633orientation instead of assuming one specific orientation.</p>
634
635<p>If your application uses the orientation sensors, such as the accelerometer (with the {@link
636android.hardware.SensorManager} APIs), also be aware that the landscape screen can also cause
637problems, due to false assumptions about which orientation is the natural position. For more
638information about how you should properly handle rotation changes when using the orientation
639sensors, read the blog post, <a
640href="http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html">One
641Screen Turn Deserves Another</a>.</p>
642
643
644
645<h3 id="Telephony">Using telephony or other variable features</h3>
646
647<p>Tablets and similar devices might not include support for telephony, so they can't make
648traditional phone calls or handle SMS. Some devices might also omit
649other hardware features, such as Bluetooth. If your application uses these features, then your
650manifest file probably already includes (or should include) a declaration of the feature with the <a
651href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code &lt;uses-feature&gt;}</a>
652element. Doing so prevents devices that do not declare support for the feature from downloading
653your applications. For example:</p>
654
655<pre>&lt;uses-feature android:name="android.hardware.telephony" /></pre>
656
657<p>By default, this declares that your application <em>requires</em> telephony features. So,
658external services such as Android Market use this information to filter your application from
659devices that do not offer telephony.</p>
660
661<p>If, however, your application uses, but does not require the feature, you should
662add to this element, {@code android:required="false"}. For example:</p>
663
664<pre>&lt;uses-feature android:name="android.hardware.telephony" android:required="false" /></pre>
665
666<p>This indicates that your application uses the feature, but is still functional if the feature is
667not available. So, it should still be available to devices that don't provide telephony hardware
668(or telephony features), such as tablets.</p>
669
670<p>Then in your application code, you must gracefully disable the features that use telephony
671when it's not available. You can check whether the feature is available using {@link
672android.content.pm.PackageManager#hasSystemFeature PackageManager.hasSystemFeature()}. For
673example:</p>
674
675<pre>
676PackageManager pm = getPackageManager();
677boolean hasTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
678</pre>
679
680<p>For more information about these
681issues and how to future-proof your application for different hardware, read the blog post <a
682href="http://android-developers.blogspot.com/2010/10/five-steps-to-future-hardware-happiness.html">
683The Five Steps to Future Hardware Happiness</a>.</p>