Android developer Guide (7) -- App Install Location

Source: Internet
Author: User
Tags home screen

 

Preface

This chapter is the developer Guide/Developing/Appendix/App Install Location, version: Android3.0 r1, translated from "madgoat", welcome to its blog: "http://madgoat.cn ", thanks again for "madgoat "! We look forward to your participation in translation of Android related information, contact me over140@gmail.com.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog Garden: http://www.cnblogs.com/

Android Chinese translation group: http://goo.gl/6vJQl

 

Original

Http://developer.android.com/guide/appendix/install-location.html

 

Body

From API Level 8, you can allow your applications to be installed to extended storage (for example, SD card ). This is an optional feature. You can use the manifest attribute in your application.android:installLocation. If you do not set this attribute, your application will be installed in the internal storage and cannot be moved to the extended storage.

To allow the system to install your application on the extended storage, modify your manifest file and include the android: installLocation attribute in the <manifest> element, set the value to "preferExternal" or "auto ". For example:

<Manifest xmlns: android = http://schemas.android.com/apk/res/android

Android: installLocation = "preferExternal"

...>

If you define "preferExternal", it means that you require your application to be installed in extended storage, but the system cannot guarantee that the application will be installed in extended storage. If the extended storage has no space, the system will install the application to the internal storage. You can move your application between two locations.

If you define "auto", your application may be installed in the extended storage, but there is no special preference for the installation location. The system determines where your application is installed based on many factors. You can also move an application between two locations.

When your application is installed on extended storage:

* As long as the extended storage is attached to a device, the performance of the application is not affected.

*.The apk file is stored in extended storage, but all user private data, databases, optimized. dex files, and released native code are stored in the internal storage space.

* The only container for storing your application is encrypted and stored by a randomly generated KEY. It can only be decrypted by the device that was originally installed. Therefore, an application installed on the SD card can only work on one device.

* You can move your applications to the internal storage through the system settings.

Warning:When you Enable USB high-capacity storage to share files to your computer or uninstall the SD card through system settings, the external storage is detached from the device and all applications running on the external storage are immediately ended.

Backward compatibilityBackward Compatibility

The function of installing your application to extended storage is effective only when devices of API Level 8 (Android 2.2) and later are running. Existing applications compiled using versions earlier than API Level 8 will be installed in the internal storage all the time, and cannot be moved to extended storage (even if the device is running an API Level 8 system ). However, if your application plans to support API levels lower than 8, you can choose to support this feature for API Level 8 and later, and continue to be compatible with devices lower than the API Level 8.

To allow installation in extended storage and maintain compatibility with API Level 8 or earlier:

* In<manifest>Contains the android: installLocation attribute with the value "auto" or "preferExternal.

* Keep your android: minSdkVersion attributes unchanged (less than 8 values) and make sure your application code only uses APIs that are compatible with this level.

* To compile your application, change your build target to API Level 8. This step is required because the old Android library cannot understand the android: installLocation attribute, and your application will not be compiled when this attribute exists.

When your application is installed on a device with an API Level lower than 8, the android: installLocation attribute is ignored and the application is installed on the internal storage.

Note:Although the XML tag, for example, will be ignored by the previous platform, you should be careful not to use the programming API in API Level 8 unless you provide backward compatibility in your code. For more information about how to create Backward Compatibility in application code, see Backward Compatibility.

Applications that should not be installed in extended storage

Applications That shoshould NOT Install on External Storage

When users Enable USB bulk storage to share files with their computers (detach or remove the extended storage), any applications installed on the extended storage and running will be terminated. In fact, the system does not know the existence of the application until the large-capacity storage is disabled, or the extended storage is remounted to the device. In addition to killing the application and making it unavailable to users, it also interrupts some types of applications in a more serious way. To keep your application running as expected, when you use any of the following features, you should not allow your application to be installed on extended storage, to avoid the consequences of uninstalling the extended storage:

Services

When the extended storage is detached, you are runningServiceIt will be stopped and will not be restarted. You can registerACTION_EXTERNAL_APPLICATIONS_AVAILABLEBroadcast (broadcast) Intent will notify your application when the application installed on the extended storage is valid for the system again. At that time, you can restart your Service.

Scheduled service Alarm Services

You registeredAlarmManagerWill be canceled. When the extended storage is remounted, you must manually re-register it.

Input Method Engines

Your input method (IME) will be replaced with the default input method. When the extended storage is remounted, you can enable system settings to re-enable your input method.

Wallpaper Live Wallpapers

The Live Wallpaper you are running will be replaced with the default one. When the extended storage is attached, you can select Live Wallpaper again.

Live Folders

Your Live Folder will be removed from the home screen. When the extended storage is attached, you can re-add Live Folder to the Home interface.

App widget App Widgets

Your App widgets will be removed from the Home interface. When the extended storage is mounted, you will not be able to use your App widgets (usually until the system restarts) until the Home application is reset ).

Account Managers

Before the extended storage is attachedAccountManagerThe created accounts are invisible.

Sync Adapters

Before the extended storage is attachedAbstractThreadedSyncAdapterAnd all related synchronization functions will not work.

Device Administrators

YourDeviceAdminReceiverAnd its management capabilities will be disabled, which will lead to unexpected results of device functions, this phenomenon will continue until the extended storage is remounted.

Broadcast Receivers listening for "boot completed"

T system sends broadcast before the extended storage is mounted to the deviceACTION_BOOT_COMPLETED. So if your application is installed on the extended storage, it will not receive this broadcast.

If your application uses any of the features listed above, you should not allow your application to be installed on extended storage. By default, the system will not allow your applications to be installed in extended storage, so you do not need to worry about your existing applications. However, if you are not sure whether your application will never be installed on the extended storage, you can defineandroid:installLocationThe value is "internalOnly" to ensure that it is installed in the internal storage. Although this does not change the default behavior, it makes it clear that your application will only be installed on the internal storage and serves as a reminder that you and other developers have made a decision.

 

Applications that should be installed in extended storage

Applications That shoshould Install on External Storage

Simply put, any application that does not use the function list in the previous section installed on the extended storage is secure. Large Games are more common application types that should be installed to extended storage, because games do not need to provide additional services when they are in a non-active state. When the extended storage is invalid, the game process is terminated, which does not significantly affect the storage, you can restart the game (assuming that the game is saved in the normal Activity lifecycle ).

If the APK file size of your application is several megabytes (MB), you need to carefully consider whether to enable application installation to extended storage, so that users can retain their internal storage space.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.