Android basics --- mind map (updated)

Sharing records Android learning review process

Insert picture description here

Basic components

Activity

View

  • overall arrangement

    • AbsoluteLayout

    • ConstraintLayout

      • Strong equipment adaptability
    • LinearLayout

  • List display

    • ListView (obsolete)

      • Reason: Developers need to optimize the performance of getChildView(), getGroupView(), otherwise ListView is prone to lag
    • RecyclerView (recommended)

      • Mandatory use ViewHolder to manage all sub-components in convertView for good performance
  • progress bar

    • ProgressBar
  • Drag bar

    • SeekBar
    • RatingBar
  • View effect

    • ViewAnimator

      • Add animation effects

        • ViewFilpper

          • Animation effect of controlling component switching
    • ViewSwitcher

      • Switch view

        • ImageSwitcher
        • TextSwitcher
  • System status bar notification

    • NotificationManager

      • Send Notification through Manager
    • Channel (Android 8 added)

      • Unified management notice
    • Starting with Android 9,

  1. Person should be used as a parameter when creating MessageStyle to set richer information
  2. Message object can use setData() to set more various notification data (such as pictures)
  • Dialog box

    • AlertDialog

      • ProgressDialog
      • DatePickerDialog
      • TimePickerDialog

Service

BroadcastReceiver

ContentProvider

Intent & IntentFilter

Android event mechanism

Event handling

  • Monitoring-based event handling

    • Binding a specific time listener (Listener) for the component

      • Application scenarios: scenarios that
        cannot be based on callbacks=.=
      • Three objects of monitoring processing:
  1. Event Source: component
  2. Event: User action
  3. Event Listener: listen for events from the event source and respond
  • Event handling based on callback

    • Override the callback method of the component/activity

      • Application scenario:
        handling events with generality
      • Taking View as an example, its callback methods are:
        onKeyDown(), onKeyLongPress(), onKeyShortCut(), onKeyUp(), onKeyTouchEvent(), onTrackballEvent()

Respond to events set by the system

  • Configuration class

    • Get system configuration information

Large volume and complex data processing

  • Handler messaging mechanism

    • main effect

      • Send a message in the newly started thread
      • Obtain and process messages in the main thread (UI thread)
    • Handler、Loop、MessageQueue

      • Message:
        The message object received and processed by the Handler

      • Looper:
        Each thread can only have one Looper, the loop method is responsible for reading the message in the MessageQueue, and sending the message to the Handler for processing after reading the message

      • MessageQueue:
        Message queue, first-in first-out management Message object, when the program creates a Looper object, it will create a MessageQueue object in its constructor

      • Handler:
        Send messages to the specified MessageQueue, that is, there must be a Looper object in the current thread to manage the MessageQueue

        • Ensure that there are Looper objects in the thread:
  1. In the main UI thread, the system has initialized a Looper object

  2. Self-started child threads, Bixi creates a Looper object and calls its prepare() method. The prepare() method ensures that each thread has at most one Looper object

    • Handler use steps:
  3. Call Looper's prepare() method to create Looper object

  4. Create an instance of Handler and override the handleMessage() method, which is responsible for processing messages from other threads

  5. Call Looper's loop() method to start Looper

Simple data processing

  • AsyncTask

    • Handling lightweight tasks
    • Compared with Handler, it consumes more system resources

Activity and Fragment

Activity

  • Activity start

    • Start Activity through Intent
    • Exchange data between activities through Bundle
  • Activity callback mechanism

    • Free theme

UI thread blocking for more than 20s will cause ANR (Application Not Responding) exception

Solutions:

Reduce the time-consuming operation of the UI thread, and put the time-consuming operation on the child thread

Guess you like

Origin blog.csdn.net/weixin_45356787/article/details/113718233