-2

I am trying to pass data more than 1Mb here, data it may be possible bitmap or string so, android.os.TransactionTooLarge exception thrown by an application but below 24 API level it was a simple warning but >=24 API level it will create application crash so, how can I know this transaction is valid or not else have any API available which represents this transaction is valid or not?. Can I prior know the transaction is valid or not?

for example,

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is too long string data...");
startActivity(sendIntent);
Kishan Donga
  • 2,851
  • 2
  • 23
  • 35
  • Which transactions are you talking about? Fragment, database, ... – Henry Dec 06 '17 at 08:28
  • using Intent I am passing data from one app to other app – Kishan Donga Dec 06 '17 at 08:29
  • Possible duplicate of [Maximum length of Intent putExtra method? (Force close)](https://stackoverflow.com/questions/12496700/maximum-length-of-intent-putextra-method-force-close) – Henry Dec 06 '17 at 08:32
  • possible is not a duplication of Maximum ... because I am just trying to ask IPC binder have an API? so, we can know is a valid transaction or not. – Kishan Donga Dec 06 '17 at 08:42

2 Answers2

0

Its not api dependents, its a bundle restriction that you cannot transfer data above 1MB.

I am not sure about the data type you are talking about but you have to persist it and then share it(like some sort of url)

Arpit
  • 1,259
  • 11
  • 21
0

If you really need to measure the size of the String or Bitmap you can get its byte array and count as per this link.

In your case you probably should not pass these objects in bundles between activities. Instead you can put it in a Singleton object, put it in an LRU cache or persist it.

If you need to keep your object intact even if the app's process dies, than your only option is persisting it.

BMacedo
  • 768
  • 4
  • 10
  • yes, this one valid first I am measure bytes and then after doing transaction but if I want to pass data more then 1MB to the other application then? – Kishan Donga Dec 06 '17 at 08:49
  • If it's between apps the same principle applies. You need to persist it in a public way (be it a file in the external dir or a public shared preferences) and consume from that location in the other app – BMacedo Dec 06 '17 at 08:53
  • Or if you passing data like social media app like WhatsApp or FB then? – Kishan Donga Dec 06 '17 at 08:55
  • I think we need to compulsorily focus on the size of a transaction. – Kishan Donga Dec 06 '17 at 08:57
  • When you share large images or videos through WhatsApp, Facebook or other app you actually send just the file path where it is stored. You don't create an intent with the whole object serialized inside. – BMacedo Dec 06 '17 at 08:59
  • But if you want to check the size of the bundled object, check the String and Bitmap size as per the link in the answer and sum up the size of each parameter bundled. If it's larger than 1Mb then drop it programmatically. – BMacedo Dec 06 '17 at 09:02
  • have any example or link? I will try to share large data using social media apps – Kishan Donga Dec 06 '17 at 09:03