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