Sharing records Android learning review process
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,
-
- Person should be used as a parameter when creating MessageStyle to set richer information
- 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:
- Application scenarios: scenarios that
-
- Event Source: component
- Event: User action
- 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()
- Application scenario:
-
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:
-
-
-
In the main UI thread, the system has initialized a Looper object
-
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:
-
Call Looper's prepare() method to create Looper object
-
Create an instance of Handler and override the handleMessage() method, which is responsible for processing messages from other threads
-
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