The first line of code - Second Edition - after viewing

Chapter 1 Introduction to Android

  • as is based on idea. No wonder it's so similar
  • proguard-rules.pro is a file that specifies the confusion rules of the project code (confusion is that the project is typed into an installation package and does not want to be cracked, so as to confuse and make it difficult for the cracker to read)
  • gradle is based on grovvy's domain specific language (DLS) to declare project settings, not xml

The second chapter starts with the visible - inquiry activities  

page:47

  • When we register activities in the manifest file, sometimes we can write the class name directly because the package attribute in the tag manifest has declared the current package name
  • There are two ways to start an activity: explicit and implicit. The explicit way is what we usually use most (as follows), which directly indicates the activity to jump; Implicitly, it needs to be in the registration list
   startActivity(Intent(this, MainActivity::class.java))
  • startActivityFOrResult() is used to return data to the previous interface   page64  
  • Activity status: an activity can h have up to 4 statuses:
    • Running: it can be seen that the running is at the top of the stack
    • Pause: visible, suspended, not at the top of the stack. For example, in the interface below the pop-up dialog box, the system will recycle only when the memory is very low
    • Stop: invisible and stopped, which may be recycled by the system
    • Destroy: those removed from the stack and in the destroyed state are most likely to be recycled by the system
  • Activities in the stopped state may be recycled by the system. After recycling, the system returns to this interface again to call back and recreate the interface with onCreate(). However, the interface data is no longer available. At this time, it is necessary to call onSaveInstanceState() to assign values before recycling, and then obtain parameters from the bundle parameter of the interface created in the onCreate() method.   page:74
  • Active startup mode Please refer to an article I wrote before
    • But in fact, i didn't quite understand the usage of SingleInstance before. SingleInstance is equivalent to re creating A stack to manage activities. It can be seen from figure 2.41 in the first line of code, section 5 of Chapter 2 - when setting the lauchMode to SingleInstance for B, jump from A to B, and then from B to C. The taskId of A is the same as that of C, and B is different from AC. therefore, it can also be seen that B is managed by A separate stack; First, when you click back from C, C comes out of the stack and A comes to the top of the stack, so A will be displayed. Click back again, A comes out of the stack, and only B's stack is left, so B will be displayed.
  • Kill process: Android os. Progree. killProgress(android.os.progress.myPid)   page 84

Chapter III 20-8-17

  • A new attribute of the Button button is found: textAllCaps. The default is true. The text is automatically capitalized   page100
  • page121 3.4.2
  • page 143
  • After chapter 3 of page 152, figure. 9 in front of 20-8-25 needs to be well understood and practiced. Combined with the last chat interface (d), I also want to write a ha
    //Position the rv to the last row
    rv.scrollToPosition(position:Int)
  • 20-8-26 page166

Chapter 4: fragment

  • You can also write down the instance of fragment and the use of fragment life cycle

Chapter V: Broadcasting

  • 20-8-31 page180 5.1 broadcast
  • Dynamically register a broadcast receiver
    • Disadvantages: the broadcast can only be received after the project is started
    • Advantages: more flexible registration and cancellation
    //Intent filter
    private lateinit var intentFilter: IntentFilter
    private lateinit var myBroadCastReceiver: MyBroadCastReceiver

    myBroadCastReceiver = MyBroadCastReceiver()
        //After registering a broadcast to monitor network changes, when the network is disconnected and connected, the message will be received in onReceive(), and the processing logic will also be processed in this
        registerReceiver(myBroadCastReceiver, IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"))

    /**
     * Create a new broadcast receiver
     */
    class MyBroadCastReceiver : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent?) {
            Log.d("ippx", "onReceive: okin=====")
        }
    }
  • Statically register a broadcast
    • Disadvantages: the control registration can only be in the manifest, which is relatively less flexible
    • Advantages: you can receive the broadcast before the program starts
    eg: Monitor a boot permission
    
    <!--   Monitoring system startup permission-->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    
       <receiver
            android:name=".broadcast.MyReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
        
    class MyReceiver : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            // This method is called when the BroadcastReceiver is receiving an Intent broadcast.
            Log.d("ippx", "onReceive: Monitor that the system is turned on~~~~~~~~~~~~")
        }
    }
    
    Re run the program, shut down and restart. After the mobile phone is restarted, you can see MyReceiver of onReceive Print in
  • Send a custom broadcast
    class SelfDefinedBroadCastReceiver : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            Log.d("ippx", "onReceive: receive a self defined broadcast ")
        }
    }

    private val receiver = SelfDefinedBroadCastReceiver()
    
    //Dynamically register a broadcast receiver
    val intentFilter = IntentFilter("intent_filter")
    registerReceiver(receiver,intentFilter)
    
    sendBroadcast(Intent("intent_filter"))
  • Broadcast is also a way of cross process communication (all four components of Android can carry out cross process communication: activity, service, broadCastReceiver and contentProvider), and aidl can also
  • The above are all standard broadcasts sent. Broadcasts are divided into standard broadcasts and orderly broadcasts.
    //Send an ordered broadcast, and set the priority so that the receiver with lower priority cannot receive the broadcast
    private val receiver = SelfDefinedBroadCastReceiver()
    private val selfDefinedIntentFilter = IntentFilter("intent_filter")
    
    selfDefinedIntentFilter.priority = 100
    registerReceiver(receiver, selfDefinedIntentFilter)

    //Parameter 1: action; parameter 2: permission related string; null here
    sendOrderedBroadcast(Intent("intent_filter"), null)

Correlation code portal

Tags: Android kotlin AndroidStudio

Posted by dpacmittal on Thu, 19 May 2022 14:19:03 +0300