1page.title=Android 4.2 APIs 2excludeFromSuggestions=true 3sdk.platform.version=4.2 4sdk.platform.apiLevel=17 5@jd:body 6 7<div id="qv-wrapper"> 8<div id="qv"> 9 10<h2>In this document</h2> 11<ol> 12 <li><a href="#Behaviors">Important Behavior Changes</a></li> 13 <li><a href="#Daydream">Daydream</a></li> 14 <li><a href="#SecondaryDisplays">Secondary Displays</a></li> 15 <li><a href="#Lockscreen">Lockscreen Widgets</a></li> 16 <li><a href="#MultipleUsers">Multiple Users</a></li> 17 <li><a href="#RTL">RTL Layout Support</a></li> 18 <li><a href="#NestedFragments">Nested Fragments</a></li> 19 <li><a href="#Renderscript">Renderscript</a></li> 20</ol> 21 22<h2>See also</h2> 23<ol> 24<li><a 25href="{@docRoot}sdk/api_diff/17/changes.html">API 26Differences Report »</a> </li> 27</ol> 28 29</div> 30</div> 31 32 33<p>API Level: 17</p> 34 35<p>Android 4.2 ({@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}) 36is an update to the Jelly Bean release that offers new features for users and app 37developers. This document provides an introduction to the most notable and 38useful new APIs for developers.</p> 39 40<p>As an app developer, you should download the Android 4.2 system image and SDK platform from 41the <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a> as soon as possible. If you 42don’t have a device running Android 4.2 on which to test your app, use the Android 4.2 system 43image to test your app on the <a href="{@docRoot}tools/devices/emulator.html">Android emulator</a>. 44Then build your apps against the Android 4.2 platform to begin using the latest APIs.</p> 45 46 47 48<div class="sidebox-wrapper"> 49<div class="sidebox"> 50 51<h3 id="ApiLevel">Declare your app API Level</h3> 52 53<p>To better optimize your app for devices running Android {@sdkPlatformVersion}, 54 you should set your <a 55href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> to 56<code>"{@sdkPlatformApiLevel}"</code>, install it on an Android {@sdkPlatformVersion} system image, 57test it, then publish an update with this change.</p> 58 59<p>You 60can use APIs in Android {@sdkPlatformVersion} while also supporting older versions by adding 61conditions to your code that check for the system API level before executing 62APIs not supported by your <a 63href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code minSdkVersion}</a>. 64To learn more about 65maintaining backward-compatibility, read <a 66href="{@docRoot}training/backward-compatible-ui/index.html">Creating Backward-Compatible 67UIs</a>.</p> 68 69<p>More information about how API levels work is available in <a 70href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">What is API 71Level?</a></p> 72 73</div> 74</div> 75 76 77 78 79<h2 id="Behaviors">Important Behavior Changes</h2> 80 81<p>If you have previously published an app for Android, be aware of the following 82changes that might affect your app’s behavior:</p> 83 84<ul> 85 <li><b>Content providers</b> are no longer exported by default. That is, the default value 86for the <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported">{@code 87android:exported}</a> attribute is now {@code “false"}. If it’s important that other apps be 88able to access your content provider, you must now explicitly set <a 89href="{@docRoot}guide/topics/manifest/provider-element.html#exported">{@code 90android:exported="true"}.</a> 91 <p>This change takes effect only if you set either <a 92 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code 93android:targetSdkVersion}</a> or <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 94android:minSdkVersion}</a> to 17 or higher. Otherwise, the default value is still {@code “true"} 95even when running on Android 4.2 and higher.</p> 96 </li> 97 98 <li>Compared to previous versions of Android, <b>user location</b> results may be less accurate 99if your app requests the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} permission but 100does not request the {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission. 101 <p>To meet the privacy expectations of users when your app requests permission for 102coarse location (and not fine location), the system will not provide a user location estimate 103that’s more accurate than a city block.</p> 104 </li> 105 106 <li>Some <b>device settings</b> defined by {@link android.provider.Settings.System} are now 107 read-only. If your app attempts to write changes to settings defined in {@link 108 android.provider.Settings.System} that have moved to {@link android.provider.Settings.Global}, 109 the write operation will silently fail when running on Android 4.2 and higher. 110 <p>Even if your value for <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code 111android:targetSdkVersion}</a> and <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 112android:minSdkVersion}</a> is lower than 17, your app is not able to modify the settings that have 113moved to {@link android.provider.Settings.Global} when running on Android 4.2 and higher.</p> 114 </li> 115 116 <li>If your app uses {@link android.webkit.WebView}, Android 4.2 adds an additional layer of 117 security so you can more safely <b>bind JavaScript to your 118 Android code</b>. If you set your 119 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> 120 to 17 or higher, you must now add the {@code @JavascriptInterface} annotation to any method that you 121 want available to your JavaScript (the method must also be public). If you do not provide the 122 annotation, the method is not accessible by a web page in your {@link android.webkit.WebView} 123 when running on Android 4.2 or higher. If you set the 124 <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code targetSdkVersion}</a> 125 to 16 or lower, the annotation is not required, but we recommend that you update your target version 126 and add the annotation for additional security. 127 <p>Read more about <a href="{@docRoot}guide/webapps/webview.html#BindingJavaScript">binding 128 JavaScript code to Android code</a>.</p></li> 129</ul> 130 131 132 133 134 135 136<h2 id="Daydream">Daydream</h2> 137 138<p>Daydream is a new interactive screensaver mode for Android devices. It activates automatically 139when the device is inserted into a dock or when the device is left idle while plugged in to a 140charger (instead of turning the screen off). Daydream displays one dream at a time, which may 141be a purely visual, passive display that dismisses upon touch, or may be interactive and responsive 142to the full suite of input events. Your dreams run in your app’s process and have full access to 143the Android UI toolkit, including views, layouts, and animations, so they are more flexible and 144powerful than either live wallpapers or app widgets.</p> 145 146<p>You can create a dream for Daydream by implementing a subclass of {@link 147android.service.dreams.DreamService}. The {@link android.service.dreams.DreamService} APIs are 148designed to be similar to those of {@link android.app.Activity}. To specify the UI for your 149dream, pass a layout resource ID or {@link android.view.View} to {@link 150android.service.dreams.DreamService#setContentView setContentView()} at any point after you have 151a window, such as from the {@link android.service.dreams.DreamService#onAttachedToWindow()} 152callback.</p> 153 154<p>The {@link android.service.dreams.DreamService} class provides other important lifecycle callback 155methods on top of the base {@link android.app.Service} APIs, such as {@link 156android.service.dreams.DreamService#onDreamingStarted()}, {@link 157android.service.dreams.DreamService#onDreamingStopped()}, and {@link 158android.service.dreams.DreamService#onDetachedFromWindow()}. 159You cannot initiate a {@link android.service.dreams.DreamService} from your 160app—it is launched automatically by the system.</p> 161 162<p>If your dream is interactive, you can start an activity from the dream to send the user into 163your app’s full UI for more detail or control. You can use {@link 164android.service.dreams.DreamService#finish()} to end the dream so the user can see the 165new Activity.</p> 166 167<p>To make your daydream available to the system, declare your {@link 168android.service.dreams.DreamService} with a <a 169href="{@docRoot}guide/topics/manifest/service-element.html">{@code <service>}</a> element 170in your manifest file. You must then include an intent filter with the action {@code 171"android.service.dreams.DreamService"}. For example:</p> 172 173<pre> 174<service android:name=".MyDream" android:exported="true" 175 android:icon="@drawable/dream_icon" android:label="@string/dream_label" > 176 <intent-filter> 177 <action android:name="android.service.dreams.DreamService" /> 178 <category android:name="android.intent.category.DEFAULT" /> 179 </intent-filter> 180</service> 181</pre> 182 183<p>There are some other useful methods in {@link android.service.dreams.DreamService} 184to be aware of:</p> 185 186<ul> 187 <li>{@link android.service.dreams.DreamService#setInteractive(boolean)} controls whether 188the dream receives input events or exits immediately upon user input. If the dream is 189interactive, the user may use the <em>Back</em> or <em>Home</em> buttons to exit the dream or you can call 190{@link android.service.dreams.DreamService#finish()} to stop the dream.</li> 191 <li>If you want a fully immersive display, you can call {@link 192android.service.dreams.DreamService#setFullscreen 193setFullscreen()} to hide the status bar.</li> 194 <li>Before Daydream starts, the display dims to signal to the user that the idle timeout 195is approaching. Calling {@link android.service.dreams.DreamService#setScreenBright 196setScreenBright(true)} allows you to instead set the display at its usual brightness.</li> 197</ul> 198 199<p>For more information, see the {@link android.service.dreams.DreamService} documentation.</p> 200 201 202 203 204 205 206 207 208 209 210 211<h2 id="SecondaryDisplays">Secondary Displays</h2> 212 213<p>Android now allows your app to display unique content on additional screens that are connected 214to the user’s device over either a wired connection or Wi-Fi. 215 To create unique content for a secondary display, extend the {@link android.app.Presentation} 216class and implement the {@link android.app.Presentation#onCreate onCreate()} callback. Within 217{@link android.app.Presentation#onCreate onCreate()}, specify your UI for the secondary display 218by calling {@link android.app.Presentation#setContentView setContentView()}. 219As an extension of the {@link android.app.Dialog} class, the {@link 220android.app.Presentation} class provides the region in which your app can display a unique UI on the 221secondary display.</p> 222 223<p>To detect secondary displays where you can display your {@link android.app.Presentation}, 224use either the {@link android.hardware.display.DisplayManager} or {@link android.media.MediaRouter} 225APIs. While the {@link android.hardware.display.DisplayManager} APIs allow you to enumerate 226multiple displays that may be connected at once, you should usually use {@link 227android.media.MediaRouter} instead to quickly access the system’s default display for 228presentations.</p> 229 230<p>To get the default display for your presentation, call {@link 231android.media.MediaRouter#getSelectedRoute MediaRouter.getSelectedRoute()} and pass it 232{@link android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO}. This returns a {@link 233android.media.MediaRouter.RouteInfo} object that describes the system’s currently selected route 234for video presentations. If the {@link android.media.MediaRouter.RouteInfo} is not null, call 235{@link android.media.MediaRouter.RouteInfo#getPresentationDisplay()} to get the {@link 236android.view.Display} representing the connected display.</p> 237 238<p>You can then display your presentation by passing the {@link android.view.Display} object 239to a constructor for your {@link android.app.Presentation} class. Your presentation will now 240appear on the secondary display.</p> 241 242<p>To detect at runtime when a new display has been connected, create an instance of {@link 243android.media.MediaRouter.SimpleCallback} in which you implement the {@link 244android.media.MediaRouter.SimpleCallback#onRoutePresentationDisplayChanged 245onRoutePresentationDisplayChanged()} callback method, which the system will call when a new 246presentation display is connected. Then register the {@link 247android.media.MediaRouter.SimpleCallback} by passing it to {@link 248android.media.MediaRouter#addCallback MediaRouter.addCallback()} along with the {@link 249android.media.MediaRouter#ROUTE_TYPE_LIVE_VIDEO} route type. When you receive a call to 250{@link android.media.MediaRouter.SimpleCallback#onRoutePresentationDisplayChanged 251onRoutePresentationDisplayChanged()}, simply call {@link 252android.media.MediaRouter#getSelectedRoute MediaRouter.getSelectedRoute()} as mentioned above.</p> 253 254<p>To further optimize the UI in your {@link android.app.Presentation} for 255secondary screens, you can apply 256a different theme by specifying the {@link 257android.R.attr#presentationTheme android:presentationTheme} attribute in the <a 258href="{@docRoot}guide/topics/resources/style-resource.html">{@code <style>}</a> that you’ve 259applied to your application or activity.</p> 260 261<p>Keep in mind that screens connected to the user’s device often have a larger screen size and 262likely a different screen density. Because the screen characteristics may different, you should 263provide resources that are optimized specifically for such larger displays. If you need 264to request additional resources from your {@link 265android.app.Presentation}, call {@link android.app.Presentation#getContext()}{@link 266android.content.Context#getResources .getResources()} to get the {@link 267android.content.res.Resources} object corresponding to the display. This provides 268the appropriate resources from your app that are best suited for the 269secondary display's screen size and density.</p> 270 271<p>For more information and some code samples, see the {@link android.app.Presentation} 272class documentation.</p> 273 274 275 276 277 278 279 280 281 282 283<h2 id="Lockscreen">Lockscreen Widgets</h2> 284 285<p>Android now allows users to add app widgets to the lock screen. To make your <a 286href="{@docRoot}guide/topics/appwidgets/index.html">App Widget</a> available for use on the 287lock screen, add the {@link android.appwidget.AppWidgetProviderInfo#widgetCategory 288android:widgetCategory} attribute to your XML file that specifies the {@link 289android.appwidget.AppWidgetProviderInfo}. This attribute supports two values: {@code home_screen} 290and {@code keyguard}. By default, the attribute is set to {@code home_screen} so users can add your 291app widget to the Home screen. If you want your app widget to be also available on the lock 292screen, add the {@code keyguard} value:</p> 293 294<pre> 295<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 296 ... 297 android:widgetCategory="keyguard|home_screen"> 298</appwidget-provider> 299</pre> 300 301<p>You should also specify an initial layout for your app widget when on the lock screen with 302the {@link android.appwidget.AppWidgetProviderInfo#initialKeyguardLayout 303android:initialKeyguardLayout} attribute. This works the same way as the {@link 304android.appwidget.AppWidgetProviderInfo#initialLayout android:initialLayout}, in that it provides 305a layout that can appear immediately until your app widget is initialized and able to update the 306layout.</p> 307 308<p>For more information about building app widgets for the lock screen, including to properly 309size your app widget when on the lock screen, see the <a 310href="{@docRoot}guide/topics/appwidgets/index.html#lockscreen">App Widgets</a> guide.</p> 311 312 313 314 315 316 317 318<h2 id="MultipleUsers">Multiple Users</h2> 319 320<p>Android now allows multiple user spaces on shareable devices such as tablets. Each user on a 321device has his or her own set of accounts, apps, system settings, files, and any other 322user-associated data.</p> 323 324<p>As an app developer, there’s nothing different you need to do in order for your app to work 325properly with multiple users on a single device. Regardless of how many users may exist on a 326device, the data your app saves for a given user is kept separate from the data your app saves 327for other users. The system keeps track of which user data belongs to the user process in which 328your app is running and provides your app access to only that user’s data and does not allow 329access to other users’ data.</p> 330 331<h3>Saving data in a multi-user environment</h3> 332 333<p>Whenever your app saves user preferences, creates a database, or writes a file to the user’s 334internal or external storage space, that data is accessible only while running as that user.</p> 335 336<p>To be certain that your app behaves properly in a multi-user environment, do not refer to your 337internal app directory or external storage location using hard-coded paths and instead always use 338the appropriate APIs:</p> 339<ul> 340 <li>For access to internal storage, use {@link android.content.Context#getFilesDir()}, {@link 341android.content.Context#getCacheDir()}, or {@link android.content.Context#openFileOutput 342openFileOutput()}.</li> 343 <li>For access to external storage, use {@link android.content.Context#getExternalFilesDir 344 getExternalFilesDir()} or {@link android.os.Environment#getExternalStoragePublicDirectory 345 getExternalStoragePublicDirectory()}. 346</ul> 347 348<p>No matter which of these APIs you use to save data for a given user, the data will not be 349accessible while running as a different user. From your app’s point of view, each user is running 350on a completely separate device.</p> 351 352<h3>Identifying users in a multi-user environment</h3> 353 354<p>If your app wants to identify unique users such as to gather analytics or create other account 355associations, you should follow the recommended practices for <a 356href="http://android-developers.blogspot.com/2011/03/identifying-app-installations.html">identifying 357unique installations</a>. By creating a new {@link java.util.UUID} when your app starts for the 358first time, you’re certain to obtain a unique ID for tracking each user, regardless of how many 359users install your app on a single device. Alternatively, you can save a local token fetched from 360your server or use the registrations ID provided by <a 361href="{@docRoot}google/gcm/index.html">Google Cloud Messaging</a>.</p> 362 363<p>Beware that if your app requests one of the hardware device identifiers (such as the WiFi MAC 364address or the {@link android.os.Build#SERIAL} number), they will provide the same value for each 365user because these identifiers are tied to the hardware and not the user. Not to mention the other 366problems these identifiers introduce as discussed in the <a 367href="http://android-developers.blogspot.com/2011/03/identifying-app-installations.html">Identifying 368App Installations</a> blog post.</p> 369 370<h3>New Global Settings</h3> 371 372<p>The system settings have been updated to support multiple users with the addition of {@link 373android.provider.Settings.Global}. This collection of settings is similar to {@link 374android.provider.Settings.Secure} settings because they are read-only, but applies globally across 375all user spaces on the device.</p> 376 377<p>Several existing settings were relocated here from either {@link 378android.provider.Settings.System} or {@link android.provider.Settings.Secure}. If your app is 379currently making changes to settings previously defined in {@link android.provider.Settings.System} 380(such as {@link android.provider.Settings.System#AIRPLANE_MODE_ON}), then you should expect that 381doing so will no longer work on a device running Android 4.2 or higher if those settings were 382moved to {@link android.provider.Settings.Global}. You can continue to read settings that are in 383{@link android.provider.Settings.Global}, but because the settings are no longer considered safe 384for apps to change, attempting to do so will fail silently and the system will write a warning to 385the system log when running your app on Android 4.2 or higher.</p> 386 387 388 389 390 391 392 393 394 395<h2 id="RTL">RTL Layout Support</h2> 396 397<p>Android now offers several APIs that allow you to build user interfaces that gracefully 398transform layout orientation to support languages that use right-to-left (RTL) UIs and reading 399direction, such as Arabic and Hebrew.</p> 400 401<p>To begin supporting RTL layouts in your app, set the {@link android.R.attr#supportsRtl 402android:supportsRtl} attribute to the {@code <application>} element in your manifest file 403and set it {@code “true"}. Once you enable this, the system will enable various RTL APIs to 404display your app with RTL layouts. For instance, the action bar will show the icon and title 405on the right side and action buttons on the left, and any layouts you’ve created with the 406framework-provided {@link android.view.View} classes will also be reversed.</p> 407 408<p>If you need to further optimize the appearance of your app when displayed with an RTL layout, 409there are two basic levels of optimization:</p> 410 411<ol> 412 <li>Convert left- and right-oriented layout properties to start- and end-oriented layout 413properties. 414 <p>For example, use {@link android.R.attr#layout_marginStart android:layout_marginStart} 415in place of {@code android:layout_marginLeft} and {@link android.R.attr#layout_marginEnd 416android:layout_marginEnd} in place of {@code android:layout_marginRight}. 417 <p>The {@link android.widget.RelativeLayout} class also provides the corresponding layout 418attributes to replace left/right positions, such as {@code android:layout_alignParentStart} to 419replace {@code android:layout_alignParentLeft} and {@code android:layout_toStartOf} instead of 420{@code android:layout_toLeftOf}. 421 </li> 422 <li>Or to provide complete optimization for RTL layouts, you can provide entirely separate 423layout files using the {@code ldrtl} resource qualifier ({@code ldrtl} stands for 424layout-direction-right-to-left}). For example, you can save your default layout files in 425{@code res/layout/} and your RTL optimized layouts in {@code res/layout-ldrtl/}. 426 <p>The {@code ldrtl} qualifier is great for drawable resources, so that you can provide 427graphics that are oriented in the direction corresponding to the reading direction.</p> 428 </li> 429</ol> 430 431<p>Various other APIs are available across the framework to support RTL layouts, such as in 432the {@link android.view.View} class so that you can implement the proper behaviors for custom 433views and in {@link android.content.res.Configuration} to query the current layout direction.</p> 434 435<p><strong>Note:</strong> If you are using SQlite and have tables or column names that are 436“number only," be 437careful: using <a href="{@docRoot}reference/java/lang/String.html#format(String, Object...)">{@code 438String.format(String, Object...)}</a> can lead to errors where the numbers 439have been converted to their Arabic equivalents if your device has been set to the Arabic locale. 440You must use <a href="{@docRoot}reference/java/lang/String.html#format(Locale,String,Object...)">{@code 441String.format(Locale,String,Object...)}</a> to ensure numbers are 442preserved as ASCII. Also use <a href="{@docRoot}reference/java/lang/String.html#format(String,int)">{@code 443String.format("%d", int)}</a> instead of using 444<a href="{@docRoot}reference/java/lang/String.html#valueOf(int)">{@code String.valueOf(int)}</a> for 445formatting numbers.</p> 446 447 448 449 450 451 452 453 454 455 456 457 458 459<h2 id="NestedFragments">Nested Fragments</h2> 460 461<p>You can now embed fragments inside fragments. This is useful for a variety of situations in 462which you want to place dynamic and re-usable UI components into a UI component that is itself 463dynamic and re-usable. For example, if you use {@link android.support.v4.view.ViewPager} to 464create fragments that swipe left and right and consume a majority of the screen space, you can 465now insert fragments into each fragment page.</p> 466 467<p>To nest a fragment, simply call {@link android.app.Fragment#getChildFragmentManager()} on 468the {@link android.app.Fragment} in which you want to add a fragment. This returns a {@link 469android.app.FragmentManager} that you can use like you normally do from the top-level activity 470to create fragment transactions. For example, here’s some code that adds a fragment from within 471an existing {@link android.app.Fragment} class:</p> 472 473<pre> 474Fragment videoFragment = new VideoPlayerFragment(); 475FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 476transaction.add(R.id.video_fragment, videoFragment).commit(); 477</pre> 478 479<p>From within a nested fragment, you can get a reference to the parent fragment by calling 480{@link android.app.Fragment#getParentFragment()}.</p> 481 482<p>The Android Support Library also now supports nested fragments, so you can implement nested 483fragment designs on Android 1.6 and higher.</p> 484 485<p><strong>Note:</strong> You cannot inflate a layout into a fragment when that layout 486includes a {@code <fragment>}. Nested fragments are only supported when added to a 487fragment dynamically.</p> 488 489 490 491 492 493 494<h2 id="Renderscript">Renderscript</h2> 495 496<p>Renderscript computation functionality has been enhanced with the following features:</p> 497<dl> 498 <dt><b>Script intrinsics</b></dt> 499 <dd><p>You can use Renderscript's built-in script intrinsics that implement 500common operations for you such as:</p> 501 <ul> 502 <li>{@link android.renderscript.ScriptIntrinsicBlend Blends}</li> 503 <li>{@link android.renderscript.ScriptIntrinsicBlur Blur}</li> 504 <li>{@link android.renderscript.ScriptIntrinsicColorMatrix Color matrix}</li> 505 <li>{@link android.renderscript.ScriptIntrinsicConvolve3x3 3x3 convolve}</li> 506 <li>{@link android.renderscript.ScriptIntrinsicConvolve5x5 5x5 convolve}</li> 507 <li>{@link android.renderscript.ScriptIntrinsicLUT Per-channel lookup table}</li> 508 <li>{@link android.renderscript.ScriptIntrinsicYuvToRGB Converting an Android YUV buffer to RGB}</li> 509 </ul> 510 <p>To use a script intrinsic, call the static <code>create()</code> method of each instrinsic 511 to create an instance of the script. You then call the available <code>set()</code> 512 methods of each script intrinsic to set any necessary inputs and options. 513 Finally, call the {@link android.renderscript.ScriptC#forEach forEach()}</code> 514 method to execute the script.</p> 515 </dd> 516 517 518<dt><b>Script Groups</b></dt> 519<dd> 520<p>{@link android.renderscript.ScriptGroup}s allow you to chain together related Renderscript 521scripts and execute them with one call.</p> 522 523<p>Use a {@link android.renderscript.ScriptGroup.Builder} to add all of the scripts to the group 524by calling {@link android.renderscript.ScriptGroup.Builder#addKernel addKernel()}. Once you 525add all the scripts, create the connections between the 526scripts by calling {@link android.renderscript.ScriptGroup.Builder#addConnection addConnection()}. 527When you are done adding the connections, call {@link android.renderscript.ScriptGroup.Builder#create create()} 528to create the script group. Before executing the script group, specify the input 529{@link android.renderscript.Allocation} and initial script to run with the 530{@link android.renderscript.ScriptGroup#setInput} method and provide the output 531{@link android.renderscript.Allocation} where the result will be written to and final script to 532run with {@link android.renderscript.ScriptGroup#setOutput setOutput()}. Finally, call 533{@link android.renderscript.ScriptGroup#execute execute()} to run the script group. 534</p> 535</dd> 536 537<dt><b>Filterscript</b></dt> 538<dd> 539<p>Filterscript defines constraints on the existing Renderscript APIs that allow the resulting code to run 540on a wider variety of processors (CPUs, GPUs, and DSPs). To create Filterscript files, create <code>.fs</code> 541files instead of <code>.rs</code> files, and specify <code>#pragma rs_fp_relaxed</code> to 542tell the Renderscript runtime your scripts do not require strict IEEE 754-2008 floating point precision. 543This precision allows flush-to-zero for denorms and round-towards-zero. In addition, your Filterscript 544scripts must not use 32-bit built-in types and must specify a custom root function by using the 545<code>__attribute__((kernel))</code> attribute because Filterscript does not support pointers, which 546the default signature of the <code>root()</code> function defines.</p> 547</dd> 548 549</dl> 550 551<p class="note"><strong>Note:</strong> Although Filterscript support is in the platform, developer 552support will be available in ADT and SDK Tools Release 21.0.1. </p> 553 554 555<p>For a detailed view of all API changes in Android 4.2, see the 556<a href="{@docRoot}sdk/api_diff/17/changes.html">API Differences Report</a>.</p> 557 558 559 560