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 Serializable
andParcelable
Does Intent have a data size limit?
There is a limit of 1MB, and the data will be stored in Bundle
, Intent
and the data in will be transmitted as an object Parcel
stored Binder
in the transaction buffer (Binder transaction buffer) of . Binder
There 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 TransactionTooLargeException
an exception.
How does Intent transfer big data?
- 1.
putBinder
You can bypass the 1MB limit and store data in shared memory
The latter method is equivalent to bypassing Intent
itself
- 2. Memory shared singleton or static variable
- 3. Persist data
- 4.EventBus