Android - Intent

1. What is the role of Intent?
2. What data types can Intent pass?
3. Does Intent have a data transfer size limit?
4. How does Intent transfer big data?

basic use

val intent = Intent(this, MainActivity::class.java).apply {
    
    
    putExtra("intent_int", 1)
    putExtra("intent_str","Android")
}
startActivity(intent)

Intent role

● Transfer data between Activities
● Transfer data from Activity to Service

What types of data can Intent pass

● Basic data types and String, and their array forms ● Objects
that implement serialization interfaces SerializableandParcelable

Does Intent have a data size limit?

There is a limit of 1MB, and the data will be stored in Bundle, Intentand the data in will be transmitted as an object Parcelstored Binderin the transaction buffer (Binder transaction buffer) of . BinderThere is a size limit of 1 MB.
When sending data via intent, care should be taken to limit the data size to a few KB. Sending too much data will cause the system to throw TransactionTooLargeExceptionan exception.

How does Intent transfer big data?

  • 1. putBinderYou can bypass the 1MB limit and store data in shared memory

The latter method is equivalent to bypassing Intentitself

  • 2. Memory shared singleton or static variable
  • 3. Persist data
  • 4.EventBus

material

Android uses Intent to transfer large data

Guess you like

Origin blog.csdn.net/Android_yh/article/details/130516423