Android programming implementation will apply forced installation to the phone memory method _android

Source: Internet
Author: User

The example in this article describes how the Android programming implementation will apply forced loading to the phone's memory. Share to everyone for your reference, specific as follows:

Android:installlocation is introduced in Froyo (Android 2.2,api level:8). By setting this property, developers and users can determine where the program is installed.

Android:installlocation is subordinate to the manifest node in Androidmanifest.xml. as follows:

<manifest xmlns:android= "http://schemas.android.com/apk/res/android"
   package= "string"
   Android: Shareduserid= "string"
   android:shareduserlabel= "string resource" 
   android:versioncode= "integer"
   Android:versionname= "string"
   android:installlocation=["Auto" | "Internalonly" | "Preferexternal"] > ...
</manifest>

Android:installlocation can be set to any of the three values of "auto", "internalonly", "preferexternal".

Auto: Programs may be installed on external storage media (for example: SD card), but the default will be installed in the phone's memory. When the phone is empty, the program will be installed on the external storage media. When the program is installed on the phone, the user can decide to put the program in the external storage media or in memory.

Internalonly: Default value. When set to this value, the program can only be installed in memory, and if the memory is empty, the program will not be installed successfully.

Preferexternal: Installs the program on an external storage medium, but the system does not guarantee that the program will be installed on the external storage medium. When external storage media is not available or empty, the program is installed into memory. The program will also be installed in memory when the for ward-locking mechanism is used Because the external store does not support this mechanism. After the program is installed, the user can freely switch the program should be on the external or internal storage media.

Note: When the program uses the Copy protection feature of Google Play, it can only be installed into memory.

When a program is installed to an external storage medium:

The ①.apk file will be moved to an external storage medium, but the program's data will still be in memory
② the container that saves the. apk file will be encrypted with a randomly generated key so that only the settings for installing the program can use the data on the external storage media.

Warning: When external storage media is uninstalled, programs installed on the external storage media will be terminated immediately!

Backward compatibility:

The android:installlocation is declared, but Android:minsdkversion is less than 8 o'clock, we compile it with a avd that is not less than Froyo, so android in a system below Froyo: The installlocation will be ignored, and no less than fro yo would use the android:installlocation we specify.

We should not install programs on external storage media when our program has the following behavior:

①Service
the service that is running will be terminated and the service will not be restarted when the external storage media is reloaded.
②Alarm Service
the alarm clock service will be canceled and the developer must re-register the alarm service after the external storage media has been reloaded.
③Input Method engines
Input method will be replaced by the system input method, when the external storage media is reloaded after the user can use the system settings to start our input method
④Live Wallpapers
Our dynamic wallpaper will be replaced by the default dynamic wallpaper. After the external storage media overload, the user can replace the back.
⑤Live Folders
Our dynamic folders will be moved out.
⑥App Widgets
Our widgets will be moved out, and our widgets are usually available only after the system reboots.
⑦ AccountManagers
accounts created with Accountmanager will disappear until the storage media is reloaded.
⑧Sync Adapters
Our sync function is available only if the external storage media is reloaded
⑨Device Administrators
our deviceadminreceiver will be invalidated.
⑩ Monitor Boot End Event
the system sends action_boot_completed broadcasts before loading the external storage media. Therefore, programs installed on external storage media will not be able to accept the power-on broadcast.

Usually, as long as we don't use the above features, we can install our program onto an external storage medium. For example, a large game program. When our apk files are several m big we should seriously consider whether to move programs to external storage media to help users save memory.

I hope this article will help you with the Android program.

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.