Solution to TransactionTooLargeException caused by passing large data in Android Intent

Recently, when I was connecting to an OCR recognition interface, I found that a TransactionTooLargeException occurred when the recognition data returned by one picture was transmitted through Intent (as for what TransactionTooLargeException is, I will not explain it here), but the data returned by other pictures can be transmitted normally. .
After comparison, it was found that abnormal pictures returned more information than normal pictures.
Assume it is the following entity class (actually it is much more complicated, with many fields and two or three levels of nesting. If it is so simple, there will generally be no exceptions). The data returned by the interface is a string of base64 encoding. All three fields of the abnormal picture are returned, but one or two fields of the normal picture are not returned, so there is no problem when transmitting.

public class Result {
    
    
    String avatar;
    String crop_avatar;
    String id_no_image;
}

Initially I tried to use new Gson().toJson(result) to convert to json, but still got an error.
There are many solutions, such as:

  1. Save it locally and read it where the intent is received.
  2. Transfer using EventBus

My solution is simple, because I don't need those fields that return base64 encoding, so I just comment out these fields in the entity class.

Guess you like

Origin blog.csdn.net/u012175780/article/details/129839766