Android Miscellaneous Notes Part 1

Since I came into contact with the "Android Programming Authoritative Development Guide 3rd Edition", I felt that I was delayed by the thick "Crazy Android Lectures", but this book can still be used. It is still a weakened version of the API development document. Yes, no, unknowingly, 80% of the book has been eaten, and there is not much nutrition, some knowledge points, make a note to remind that there is such a way to play:

  1. Switch button—Switch
  2. Autocomplete text box—AutoCompleteTextView
  3. Expandable List Component—ExpandableListView
  4. Stacked View—StackView
  5. Star Rating Bar—RatingBar
  6. ImageSwitcher/TextSwitcher—ImageSwitcher/TextSwitcher
  7. Calendar View—CalendarView
  8. Search Box—SearchView
  9. Scroll View—ScrollView
  10. Notification—Notification
  11. Activity bar—ActionBar
  12. Event handling - listening/calling back
  13. Parameter setting interface—PreferenceActivity+PreferenceFragment
  14. Intent属性—Component、Action、Category、Data、Type、Extra、Flag
  15. SurfaceView

    • Overview

      SurfaceView is a special view (View) in Android. The biggest difference between it and the usual TextView and Button is that it is not on the same view layer as its view container, and its UI display may not be in an independent The thread is completed, so the drawing of the SurfaceView will not affect the running of the main thread.

      Combining these characteristics, SurfaceView is generally used to realize the display of dynamic or more complex images and animations.

    • MVC framework for SurfaceView

      To use SurfaceView, you must understand its two other components: Surface and SurfaceHolder. The relationship between Surface, SurfaceHolder and SurfaceView is essentially the well-known MVC, or Model-View-Controller.

      Model means the model, or the data model, or more simply, the data, which is the Surface here.

      View is the view, which represents the user interaction interface, which is the SurfaceView here.

      SurfaceHolder can obviously be understood as a Controller in MVC.

    • Application scenarios

      Different from ordinary controls, SurfaceView can run outside the main thread, does not need to respond to user input in time, and will not cause ANR problems in response.

      SurfaceView is generally used for the display of complex UI and efficient images such as games, videos, and photography. Such image processing requires a separate thread to be processed.

  16. Telephony Manager—TelephonyManager
  17. SMS Manager—SmsManager
  18. Audio Manager—AudioManager
  19. Mobile Alarm Clock Service—AlarmManager
  20. Play Audio—MediaPlayer/SoundPool
  21. Play video—VideoView/[MediaPlayer+SurfaceView]
  22. Record audio and video—MediaRecorder
  23. 3D graphics rendering - OpenGL ES [mobile device]
  24. Network communication - Socket/ServerSocket [TCP protocol C/S] + multi-threading + URL + HTTP + WebView + Web Service [Android client interacts with remote server, SOAP/WSDL/UDDI]
  25. Desktop—Live Wallpapers [live wallpapers], shortcuts, AppWidgetProvider/RemoteViews/ComponentName/AppWidgetManager/RemoteViewsService/RemoteViewsFactory [desktop applet]
  26. Sensor - A sensor is a physical device or biological organ that can detect and sense external signals, physical conditions (such as light, heat, humidity) or chemical composition (such as smoke), and transmit the detected information to other devices or organs.

    In Android, the sensor can display the application of the current mobile phone status, including hardware information, current position, accelerometer, gyroscope, light perception, magnetic field, orientation, battery sill, sound pressure, and can also perform multi-touch tests.

    The Android platform supports three categories of sensors

    • Motion sensors

      These sensors measure acceleration forces and rotational forces along three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotation vector sensors.

    • Environmental sensors

      These sensors measure various environmental parameters such as ambient air temperature and pressure, lighting and humidity. This category includes barometers, photometers, and thermometers.

    • Position sensors

      These sensors measure the physical location of the device. This category includes orientation sensors and magnetometers.

      ※Heart rate sensor—the principle of heart rate measurement by smart bracelet

      Generally speaking, the principles of heart rate monitoring are usually divided into three types: one is the photoelectric transmission measurement method. In principle, the sensor that is in contact with the skin will emit a beam of light on the skin to measure the reflected/transmitted light. Because blood absorbs light of a specific wavelength, every time the heart pumps blood, that wavelength is absorbed in large quantities, and the heartbeat is determined. However, the disadvantage is that it consumes a lot of power and is disturbed by ambient light. At present, most of the functions of smart bracelets or watches on the market to monitor heart rate use the photoelectric transmission measurement method.

      Another method is to test the ECG signal. The sensor of the bracelet can judge the user's heart rate by measuring the electrical signal of myocardial contraction. The principle is similar to that of the ECG. The disadvantage is that the circuit is relatively complex, occupies a large space on the PCB, and is susceptible to electromagnetic interference. At the same time, the sensor must be close to the skin and the placement position is relatively fixed, so it is difficult to use this measurement method for bracelets.

      In addition to this, there is vibration measurement, which has only recently come out. Because every heartbeat will cause vibration of the body, this vibration is captured by a high-precision sensor, and then the heartbeat can be obtained through signal processing. Generally speaking, products such as smart cushions or smart massagers use this measurement method. Bracelets are relatively rare.

      The principle of heart rate measurement by Xiaomi bracelet is mainly:

      1. Through the principle of reflection, detect the oxygen content of human red blood cells

      2. Obtain blood pressure information by calculating the time difference between ECG detection and pulse detection by detecting the pulse conduction rate.

      3. Obtain a more accurate human body temperature value through the temperature sensing on both sides of the inside and outside

      4. Through the metabolic heat integration method, after detecting the heat generated by metabolism, blood oxygen saturation, and blood flow rate, the blood glucose concentration value is calculated. The biggest breakthrough of this principle is to realize the non-invasiveness of the physical sign data, and the interference to people is small. . Changes in blood pressure, blood sugar, and body temperature are helpful for hypertensive patients, diabetic patients, and pregnant women to detect their own body data.

  27. Leave it for later—PendingIntent

    "Asynchronous excitation", cross-process, PendingIntent is an ability provided by Android for external programs to invoke their own programs, and the life cycle is not related to the main program. External programs can only call three components through PendingIntent:

    • Activity
    • Service
    • Broadcast

    There are three usage scenarios for PendingIntent:

    • Use AlarmManager to set alarms
    • Display Notification in the system status bar
    • Display Widget on the desktop

    PendingIntent can also only be obtained through the following static methods:

    // 获取 Broadcast 关联的 PendingIntent
    PendingIntent.getBroadcast(Context context, int requestCode, Intent intent, int flags)
    
    // 获取 Activity 关联的 PendingIntent
    PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags)
    PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags, Bundle options)
    
    // 获取 Service 关联的 PendingIntent
    PendingIntent.getService(Context context, int requestCode, Intent intent, int flags)

    The meaning of getActivity() above is actually to get a PendingIntent object, and what the object will do when it is fired in the future is to start a new activity. That is, when it fires asynchronously, an action like Context.startActivity() is performed. Correspondingly, when the PendingIntent object obtained by getBroadcast() and getService() is excited, actions like Context..sendBroadcast() and Context.startService() will be performed respectively.

    PendingIntent is a reference of the system to the data to be processed, called: token; when the main program is Killed, the token will continue to exist and can continue to be used by other processes. If you want to cancel the PendingIntent, you need to call the cancel method of the PendingIntent.

    One misunderstanding of PendingIntent is:

    If a lot of PendingIntents are created, as long as the data in the extra is different, it is wrong to think that there are two different PendingIntents! ! Extras do not participate in the matching process of Intent.

    There are two ways to correctly distinguish between different PendingIntents:

    • The requestCode in the PendingIntent.getXXX(…) method is different
    • Not equal when tested by Intent.filterEquals

    Regarding the fourth parameter flags in the PendingIntent.getXXX(…) method, four commonly used FLAGs are defined in PendingIntent:

    //如果新请求的 PendingIntent 发现已经存在时,取消已存在的,用新的 PendingIntent 替换
    int FLAG_CANCEL_CURRENT
    
    //如果新请求的 PendingIntent 发现已经存在时,忽略新请求的,继续使用已存在的。日常开发中很少使用
    int FLAG_NO_CREATE
    
    //表示 PendingIntent 只能使用一次,如果已使用过,那么 getXXX(...) 将会返回 NULL 
    //也就是说同类的通知只能使用一次,后续的通知单击后无法打开。
    int FLAG_ONE_SHOT
    
    //如果新请求的 PendingIntent 发现已经存在时, 如果 Intent 有字段改变了,这更新已存在的 PendingIntent
    int FLAG_UPDATE_CURRENT
  28. GPS positioning—LocationManage service class/LocationProvider provider/Location location information abstract class (entity class)/Criteria filter condition/LocationListener

    passive: represented by the LocationManager.PASSIVE_PROVIDER constant

    gps: Represented by the LocationManager.GPS_PROVIDER constant, representing the LocationProvider object that obtains positioning information through GPS

    network: Represented by the LocationManager.NETWORK_PROVIDER constant, representing the LocationProvider object that obtains location information through the mobile communication network

    imminent warning

    There are generally three types of positioning solutions: GPS positioning, Google network positioning and base station positioning.

    The easiest way to locate a mobile phone is, of course, through a GPS module (most smartphones should have it now).

    The GPS method has the highest accuracy, but its shortcomings are also very obvious: 1. It consumes more power; 2. Most users do not turn on the GPS module by default; 3. From the start of the GPS module to the acquisition of the first positioning data, it may be necessary to A relatively long time; 4, it is almost impossible to use indoors. Among them, shortcomings 2 and 3 are more fatal. It should be pointed out that GPS takes the channel of satellite communication and can also be used without a network connection.

    Another common positioning method is base station positioning. The general idea is to collect the base station ID number (cellid) and other information (MNC, MCC, LAC, etc.) on the mobile phone, and then access some positioning services through the network to obtain and return the corresponding latitude and longitude coordinates. The accuracy of base station positioning is not as good as GPS, but the advantage is that it can be used indoors, as long as the network is smooth.

    There is also Wifi positioning. Similar to base station positioning, this method is to obtain some information about the currently used wifi, and then access the positioning service on the network to obtain the latitude and longitude coordinates. Because it and base station positioning actually need to use the network, it is also collectively referred to as the Network method in Android.

    The last thing to explain is the AGPS method. Many people confuse it with base station positioning, but in fact the essence of AGPS is still GPS, but it will use base station information to assist in acquiring GPS, and then correct the acquired GPS results, so AGPS is more efficient than traditional GPS. Fast and slightly more accurate.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325768219&siteId=291194637