The android project sets multiple icon and execution entry for an APK.

Source: Internet
Author: User

In Android development, a project corresponds to an androidmanifest. xml file, which contains some settings of the project, such as permissions, SDK activity, and service information. In general, this file has only one application node. This node indicates that this is an application, no matter how many subnodes under it, such as activity and service. In the image, after the APK generated by this project is installed on the Android device, an icon will appear in the Application List, which is the execution entry of this program.

However, in some cases, we need to set multiple execution portals for our APK, that is, multiple icon icons appear in the Application List after installation, each icon is the entry point for different app modules, and each module runs in different processes.

This requirement may be rare, but there is still a real example: the contacts and phone numbers in the system. On the surface, this is two independent applications, but they are actually only two execution portals for an application. clicking the contact icon will go to the contact interface, and clicking the phone icon will go to the dialing interface, this is achieved by setting the properties of the activity under the project.

Activity has an important attribute process, which specifies the process where the activity is running. If this attribute is not specified, all program components run in the default process of the application. The process name is consistent with the package name of the application. You can set a new default value for this component for the process attribute of all elements in. However, any component can overwrite this default value, allowing you to run your program in multiple processes. If the assigned name starts with ":", a new process dedicated to this program will be created when the activity is running.

The following code is used as an example. There are two activities in the project, one of which adopts the default attribute, and the other specifies the process attribute and the new icon, in this way, after the project is installed on the device, you can find two more application icons, one is the default application icon, and then click it to enter helloworldactivity; the other is the icon manually specified, click Next To Go To nextpageactivity. In this case, you can use the ADB shell to view the process and find that the two activities are running in different processes.

The main content of androidmanifest. XML is as follows:

<activity android:name=".HelloWorldActivity"          android:label="@string/app_name"          android:process=":process.main">         <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />         </intent-filter></activity> <activity android:name="cn.ian.NextPageActivity"  android:label="@string/nextpage"  android:process=":process.sub"  android:icon="@drawable/icon1"  android:launchMode ="singleInstance"> <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />         </intent-filter></activity>

By specifying the process and icon attributes for each component of the app, you can achieve the goal of packaging multiple programs (modules) in an APK.

PS: After you specify the process attribute for the activity, you must specify the launchmode as singleinstance.

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.