1

I copy a large text to clip board programatically.

    ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = ClipData.newPlainText("Log", log.toString());
    clipboardManager.setPrimaryClip(clipData);

If the text is too large, I get the following exception:

java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 1048812 bytes
at android.content.ClipboardManager.setPrimaryClip(ClipboardManager.java:144)

How do I know the limit and copy as much text as possible?

NoobieNoob
  • 887
  • 2
  • 11
  • 31
  • [What to do on TransactionTooLargeException](https://stackoverflow.com/q/11451393/3290339) – Onik Apr 10 '20 at 18:37

1 Answers1

0

This is sometimes a deadly error but according to documentation what are the reason this error arrives

The key to avoiding TransactionTooLargeException is to keep all transactions relatively small. Try to minimize the amount of memory needed to create a Parcel for the arguments and the return value of the remote procedure call. Avoid transferring huge arrays of strings or large bitmaps. If possible, try to break up big requests into smaller pieces.

If you are implementing a service, it may help to impose size or complexity contraints on the queries that clients can perform. For example, if the result set could become large, then don't allow the client to request more than a few records at a time. Alternately, instead of returning all of the available data all at once, return the essential information first and make the client ask for additional information later as needed.

I was facing same error because i was passing large amount of data through intents then i use static variables to set data .

Wahdat Jan
  • 3,988
  • 3
  • 21
  • 46