Five different startup methods of Activity in android

Source: Internet
Author: User
Tags home screen

We all know that the rational use of system resources to reduce the number of systems that are not occupying too much is a question that every developer must think about. As we all know, an application is composed of a series of Activities with specific functions, they have their own attributes and behaviors. You can introduce the current process to a specific Activites by starting a shortcut in the Home, or start external Activities in other program processes. Some may ask, do you know how to start a program? Of course, you can better design Activities based on your needs by understanding different startup methods.

The following describes the five design patterns related to them:

Use the shortcut icon in Home (or drop-down Application
Launcher) Startup: This is the most common startup method and represents that the program has independent operating conditions. Generally, the android. intent. category attribute of an Activity is specified as Launcher in Manifest.
Indirect startup in other programs: this reflects Activities's important feature of "reusability" in Android, for example: in the current operation, you want to send specific information to friends by Email. Generally, the system uses the default Email Activity to respond to this request, if there are other Activites similar to intent-filter in the system, an optional dialog box is provided. You can start the appropriate application as needed, this process can be viewed as an indirect startup application. You can also directly apply (startActivity () or startActivityForResult () to start a specific Activity when you predict the current system configuration.
StartActivity ():
To start an application in this way, you can see that the application runs independently in the system, and the parent that starts it does not need to get the returned value, more specifically, a Standalone application starts another program with the same Standalone features.
StartActivityForResult ():
You can intuitively see through the method naming. Its biggest role is that after an Activity is started, the parent is still associated with the Activity processed by the current process. After the operation is complete, a specific return value is returned as the result of Parent responding to certain Events. (Androidres.com)
Force a program to be started only by calling other programs (there is no direct Start entry): a considerable number of applications in the system need to have strict running conditions (Context), and cannot start with Stand.
Alone runs independently in the process. Applications with such features are generally divided into two types: 1. Applications with specific return values. As required by the current operation, parent starts other applications to obtain certain resources. For example, input method or file resource selector. In another case, it is often called to modify system settings or provide a single operation with a specific purpose. Such an Application does not need to provide a quick start method in the Home, but is only satisfied by some other programs under specific requirements. For example, change the system tone program.
A single Application contains multiple Mian
Activities have independent startup portals: many developers are used to default development configurations. An Application only contains an independent Application. This restriction can be broken under specific requirements. The system allows developers
Activities applications are bundled in the same Application, and these Main
Activities can have independent startup shortcuts in Home. However, it is important to emphasize that this method is not recommended under any circumstances, generally, when two applications need to call the same system resources or applications with most of the same functions, this method can be considered to simplify the installation process. (In another aspect, to optimize system resources ). Technically, you must note that different Main
Activity defines different tasks
Affinity. For example, Camera and Camcorder use cameras together and use Gallery as the resource manager. Their tasks
Affinity is set to com. android. camera and com. android. videocamera respectively ".
Display the application value of an Activity in the form of widgets: strictly speaking, this is indeed a startup method, some applications reference some common functions in the form of widgets in the Home or other applications (click the Home screen selection, the corresponding Application, and the system's SlidingDrawer can be reflected ).
The preceding method is used to start an Activity under different requirements in the Android system. developers can set an appropriate startup method for the Application based on specific requirements.

 

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.