The first line of code reading notes the common error analysis

Source: Internet
Author: User

In summary:What is the communication mechanism between multiple different activity in an application, and between multiple different instances of an activity?

There are usually four kinds:

Intent is used for message passing between components, and can span processes and threads. But cross-processes need to be bundled with other mechanisms (such as binder).

(Note: Thebinder mechanism is the architecture of interprocess communication implemented in Android )

Handle is typically used for updates to the main thread (UI thread) interface, which is implemented through a messaging mechanism. (need to use looper). This mechanism is typically used for thread communication.

Broadcast general and intent together, mainly for inter-process communication more.

Service is used in conjunction with intent and can be bound or unbound for interprocess communication.

?

?

Synchronization between Threads:

Synchronizing code blocks, synchronizing methods

In fact, there are some API to control the order of execution, with the lock, the simple is to let who first plug, let who first execute.

?

?

  1. Warning dialog box usage

    Note: Setcancelable can be canceled for the back button.

  2. Progress bar Usage

    To set properties:

  3. Usage of weights

    Sometimes this is used, so the button is set to Wrap_content,edittext to fill the rest of the screen

  4. Relative layout

    In a relative layout, all properties are relative to the parent control or the parent control. This needs to be clear.

    And in the layout file, all the control declarations are in order. For example, the button1 above Button3 can be referenced without declaring button3. This is wrong.

    ?

    Three sets of attributes:

    1. Relative to Parent layout:

      Layout_alignparentleft layout_alignparentright and top bottom missing layout_centerinparent

    2) relative to the control

    Layout_above below Toleftof torightof et cetera

    ?

    There is also a property that is positioned relative to the control: Layout_alignleft, and so on.

  5. Tablelayout

    You cannot specify a width for a control in this layout, we can merge cells for each row, property Layout_span

    <tablerow > Represents a row. Each control represents a column.

    There is also an important attribute that is used for adaptation, and Android:stretchcolumns=1 represents stretching the second column. 0 means that the first column is stretched.

  6. Custom controls

    Build Title_layout, and then we can put this control into other controls. As shown in the following:

    Only need to add code: <include layout= "@layout/title_layout"/>

    Of course, the system comes with a title bar that we need to hide out. Auto-hide in as. In eclipse, the attribute needs to be added: Requestwindowfeature (window.feature_no_title);

    ?

    ?

    Of course we can also add a custom control in another way:

    Build the Layoutinflater object through the Layoutinflate from () method, then call inflate to load a layout file, the parameter loads the layout file we want to add, and the second one adds a parent layout to the loaded layout file.

    Here we pass in this. Represents the specified titlelayout.

    The same as the result of the above operation.

Of course, we can also add key processing methods for custom controls, which is more flexible than include, which is used more in real development.

?

    1. Use of the ListView
      1. Writing entity classes

      2. Writing the list subkey Layout menu

      3. Write the adapter for the ListView

        Some of the following are optimized code:

      4. Add an adapter to the ListView

        ?

        Note: In the above steps, some resources need to be added themselves, such as in this example, the added resources have some pictures as follows:

    2. Layout and Text size designation

      Android rules 160dpi (screen density) in this 1DP = 1px. PX represents pixels. The DP can also be written as DPI, which indicates that the density is pixel independent. The SP is similar to DP.

      Remember: DP generally specifies the size of the control and layout. The SP specifies the size of the text.

    3. Making Nine-patch Pictures

      This is an artifact that allows you to specify which parts of a. png image can be stretched and which cannot be stretched. This application is in the SDK---tool----draw9patch.bat.

The file is named Message_left.9.png, but when we specify it in XML, it is Message_left, followed by his extension.

    1. Case: Making a chat window

      Steps: Main_layout/msg_layout, entity class, adapter class, Mount adapter

      See procedure for detailed steps.

      ?

The first line of code reading notes the common error analysis

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.