App navigation. Navigation component. App links. Dependency injection. Core topics. App compatibility. Interact with other apps. Package visibility. Intents and intent filters. User interface. Add motion to your layout with MotionLayout.
MotionLayout XML reference. Improving layout performance. Custom view components. Look and feel. Splash screens. Add the app bar. Control the system UI visibility. Supporting swipe-to-refresh. Pop-up messages overview. Adding search functionality.
Creating backward-compatible UIs. Home channels for mobile apps. App widgets. Media app architecture. Building an audio app. Building a video app. The Google Assistant. Routing between devices. Background tasks. Manage device awake state. Save to shared storage. Save data in a local database. Sharing simple data. Sharing files. Sharing files with NFC. Printing files. Content providers.
Autofill framework. Contacts provider. Data backup. Remember and authenticate users. User location. Using touch gestures. Handling keyboard input. Supporting game controllers. Input method editors.
Performing network operations. Transmit network data using Volley. Perform network operations using Cronet. Transferring data without draining the battery.
Reduce network battery drain. Transfer data using Sync Adapters. Bluetooth Low Energy. Wi-Fi infrastructure. Discover and connect. Runtime API reference. Web-based content. Android App Bundles. Google Play. Play Asset Delivery. Play Feature Delivery. In-app reviews. In-app updates. Google Play Instant. Get started with instant apps. Get started with instant games.
Integrate with Firebase. Play Install Referrer. Play Install Referrer Library. Application Licensing. Android GPU Inspector.
System profiling. Analyze a system profile. GPU performance counters. Frame profiling. Analyze a frame profile. Frame Profiler UI. Customize or port game engines.
Process input events. Support game controllers. Achieve proper frame pacing. Frame pacing in Vulkan. Integrate Android Performance Tuner. Output audio. Adaptive icons Android 8. Adaptive icons support visual effects, and can display a variety of shapes across different device models. To learn how to create adaptive icons, see the Adaptive Icons guide.
Android developers of imaging apps can now take advantage of new devices that have a wide-gamut color capable display. These APIs, which improve your app's stability and security, include the following:.
In your app, you can create pinned shortcuts and widgets for supported launchers, subject to user permission. For more information, see the Pinning Shortcuts and Widgets feature guide. First, Android 8. In addition, in Android 8. For more information about declaring maximum aspect ratio, see Supporting Multiple Screens. If an activity supports multi-window mode and is running on a device with multiple displays, users can move the activity from one display to another.
When an app launches an activity, the app can specify which display the activity should run on. Note: If an activity supports multi-window mode, Android 8. You should test your app to make sure it works adequately in a multi-display environment. Only one activity at a time can be in the resumed state, even if the app has multiple displays.
The activity with focus is in the resumed state; all other visible activities are paused, but not stopped. For more information on the activity lifecycle when several activities are visible, see Multi-Window Lifecycle. When a user moves an activity from one display to another, the system resizes the activity and issues runtime changes as necessary.
Your activity can handle the configuration change itself, or it can allow the system to destroy the process containing your activity and recreate it with the new dimensions.
For more information, see Handling Configuration Changes. ActivityOptions provides two new methods to support multiple displays:. The adb shell is extended to support multiple displays. The shell start command can now be used to launch an activity, and to specify the activity's target display:.
Specifically, you can now use the following attributes in your layout XML files:. You can set these values yourself, in addition to the new vertical and horizontal layout attributes, to create layout behavior that depends on the text direction.
Some apps, such as games, remote desktop, and virtualization clients, greatly benefit from getting control over the mouse pointer. Pointer capture is a new feature in Android 8. Starting in Android 8. The mouse pointer is hidden while in this mode. The view can release pointer capture when it doesn't need the mouse information anymore. The system can also release pointer capture when the view loses focus, for example, when the user opens another app. For information on how to use this feature in your app, see Pointer capture.
These categories are used to cluster together apps of similar purpose or function when presenting them to users, such as in Data Usage, Battery Usage, or Storage Usage.
The new home screen organizes video content in rows corresponding to channels, which are each populated with programs by an app on the system. Apps can publish multiple channels, and users can configure which channels that they wish to see on the home screen.
The Android TV home screen also includes a Watch Next row, which is populated with programs from apps, based on the viewing habits of the user. Apps can also provide video previews, which are automatically played when a user focuses on a program. Seeking lets you set the position of the animation set to a specific point in time.
Playing in reverse is useful if your app includes animations for actions that can be undone. Instead of defining two separate animation sets, you can play the same one in reverse.
If an activity in your app uses a complex view hierarchy, such as the one in Figure 2, consider organizing groups of UI elements into clusters for easier keyboard navigation among them. Good examples of clusters include: side panels, navigation bars, main content areas, and elements that could contain many child elements. Note: Clusters cannot be nested, although non-nested clusters may appear at different levels of the hierarchy.
If you attempt to nest clusters, the framework treats only the top-most ViewGroup element as a cluster. On devices that have touchscreens, you can set a cluster-designated ViewGroup object's android:touchscreenBlocksFocus element to true to allow cluster-only navigation into and out of that cluster. If you apply this configuration to a cluster, users cannot use the Tab key or arrow keys to navigate into or out of the cluster; they must press the cluster navigation keyboard combination instead.
Activities and services can use instances of TextToSpeech to dictate and pronounce content. As of Android 8. You can use this functionality to call attention to specific words as the text-to-speech engine speaks them.
To use these text-to-speech engine improvements in your app, register an instance of UtteranceProgressListener. As part of the registration process, include a handler for the onRangeStart method. The text-to-speech engine calls rangeStart to record the point in time at which it expects audio playback of a specific range of text to start. When the audio for that text range starts playback, your app's onRangeStart method executes. Your app can then respond to this callback, such as by highlighting the text range that's associated with the utterance.
For more information about tracking the playback progress of a text-to-speech engine, see the UtteranceProgressListener class reference. When the system needs to free up disk space, it will start by deleting cached files from apps that are the most over their allocated quota. Thus, if you keep your cached data under your allocated quota, your cached files will be some of the last on the system to be cleared when necessary.
When the system is deciding what cached files to delete inside your app, it will consider the oldest files first as determined by modified time. There are also two new behaviors that you can enable on a per-directory basis to control how the system frees up your cached data:. Finally, when you need to allocate disk space for large files, consider using the new allocateBytes FileDescriptor, long API, which will automatically clear cached files belonging to other apps as needed to meet your request.
When deciding if the device has enough disk space to hold your new data, call getAllocatableBytes UUID instead of using getUsableSpace , since the former will consider any cached data that the system is willing to clear on your behalf. We've updated content providers to include support for loading a large dataset one page at a time. For example, a photo app with many thousands of images can query for a subset of the data to present in a page.
Each page of results returned by a content provider is represented by a single Cursor object. You can save your variables in a bundle to pass between states. See: stackoverflow. You should not close your app as it removes all possibility of Android managing the limited resources of your device correctly. See stackoverflow. There is nothing inherently wrong with calling it, after all the call is there for a reason as there are times it is needed.
Nothing in programming is a catch-all. The worst you will do is slightly increase onCreate time by having to reload the resources again. The Android Dev blog didn't say to never use it, just that the system is designed to not normally require such a call, not that it would never be needed.
While I do agree with you in general, we can and should consider Google's statements as best practice and try to find another way. Besides, finishing an activity may not necessarily remove it from memory, and may not necessarily completely clear it's state in all current or future Android versions, but properly managing the activity will continue to work.
LeffelMania LeffelMania What if application has more than one Activity? One note if you decide to store data in the Activity as suggested here: Switching orientation mode or having pop-up interrupts that some apps provide for example, quick-view SMS apps will also stop and restart the Activity--which if data is stored only in-memory of the Activity will reset the state. So that probably isn't the solution you want in this case. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Who is building clouds for the independent developer? Exploding turkeys and how not to thaw your frozen bird: Top turkey questions
0コメント