[Android] Development Day Fourth

Source: Internet
Author: User

Introduction to the basic components of Android apps:

Activity and View

Activity is the component in the Android app that is responsible for interacting with the user.

View is the base class for all UI controls, container controls, and the view component is the real part of the Android app that users see.

The View component needs to be placed in the container component, or it can be displayed using the Activity call Setcontentview ().

The Setcontentview () method can accept a View object as a parameter, or use a resource ID.

Activity provides a visual user interface for Android apps, and if the Android app requires multiple user interfaces, it will contain multiple activities, multiple activity composition activity stacks, and currently active activity at the top of the stack.

Activity can use the setTheme (int resid) method to set the style of its window.

Service

Service is tied to Activity status, and it also represents a separate Android component. It differs from Activity in that the service is typically run in the background, and it generally does not need to interact with the user, so the service component does not have a graphical user interface.

Broadcastreceiver

Broadcastreceiver is another important component in Android apps that represents a broadcast message receiver.

As a listener, it differs from a normal event listener in that it listens to an event source that is another component in an Android app, not an object in the program.

Using the Broadcastreceiver component to receive broadcast messages is relatively straightforward, as long as developers implement their own broadcastreceiver subclasses and rewrite the onreceive (Context context,intent Intent) method.

When another component sends a broadcast message through the Sendbroadcast (), Sendstickybroadcast (), or Sendorderedbroadcast () method, the Broadcastreceiver is also "interested" in the message (by Intentfilter configuration),

Broadcastreceiver's OnReceive (context context, Intent Intent) method will be triggered.

Broadcastreceiver Registration Method:

Context.registreceiver () can be used in Java

XML can be registered using the <receiver./> element in Androidmanifest.xml.

ContentProvider

For Android apps, they must be independent and run on their own Dalvik virtual machine instances, and if they need to implement real-time data exchange between them, they need to implement their own contentprovider.

Common scenario: Our program reads the contact data from the contact management app.

To implement ContentProvider, you need to implement the following abstract methods:

Insert (Uri, contentvalues) inserts data into ContentProvider.

Delete (Uri, contentvalues) deletes the specified data in ContentProvider.

Update (Uri, Contentvalues, String, string[]) updates the specified data in the ContentProvider.

Query (Uri, string[], String, string[], string) queries the data from ContentProvider.

Typically used in conjunction with ContentProvider, a program uses ContentProvider to expose its own data, while another program uses Contentresolver to access the data.

Intent and Intentfilter

Intent is not a component in Android, but it is often used as a vehicle for communication between different components in Android applications. You need to use Intent when the Android runtime needs to connect different components.

Intent can start another Activity in the app, start the Service component, and send a broadcast message to trigger the Broadcastreceiver in the system.

That is to say, Activity, Service, broadcastreceiver communication between the three kinds of components with Intent as the carrier.

There are two types of Intent:

Display Intent: explicitly specifies the class name of the component that needs to be started or triggered.

Implicit Intent: Specifies only what conditions should be met by the component that needs to be started or triggered.

Conditions are implemented using Intentfilter.

The Android project is uniquely identified with its package name, and if two apps with the same package name are installed on the same phone, the app installed later can overwrite the previously installed app. Signatures are used to prevent different company applications from overwriting each other and protecting program integrity. command line to generate the signature: Locate the Keytool.exe tool under Jdk/bin. 1. Create KeyStore Library: Keytool-genkeypair-alias key.keystore-keyalg rsa-validity 400-keystore key.keystore-genkeypair designation Generate a digital certificate. -ALIAS Specifies the alias that generates the certificate. -keyalg the algorithm that specifies the data certificate. -validity Specifies the validity period of the certificate. -KEYSTORE Specifies the certificate store path. After entering the command, you will be prompted to fill in the details of some data certificates, which can be reused as long as the certificate is valid for a successful certificate. 2. Use Jarsigner to sign the unsigned APK installation package. (slightly) 3.  Use the Zipalign.exe tool to optimize the APK installation package. Zipalign-f-V 4 key.apk key_zip.apk-f Force overwrite an existing file-V generates verbose output 4 Specifies the number of bytes that the archive is based on, which is typically specified as 4, which is the collation based on 32 bits. key.apk key_zip.apk the apk before and after finishing. Zipalign.exe is an Android-powered archive tool that can be used to optimize the APK installation package, improve the efficiency of the interaction between Android apps and the system, and increase the speed of application operation.

[Android] Development Day Fourth

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.