Intent bundle size - android

I need to send an intent where data might be large. Since it's not possible to send intent larger than 500kb, I'd like to know the size, but there isn't any sizeof in java, how can I check the size before to send or to reduce the size?

Rather than sending data using intent declare another class "Data" to store values with static variables and use them whenever you want.

Related

The best way get Bitmap from android IntentService to get

I'm developing Web-client on Android. I use IntentService for http-request. As a result, the object are formed by IntentService which have not only the primitive types, but also, for example, Bitmap object field. Tell me, please, best way to pass the object in the Activity, or some another class.
I try used ResultReceiver, but callback method get only Bundle-object:
void onReceiveResult (int resultCode, Bundle resultData)
Bundle-object is only suitable for storing simple types. Translate large Bitmap-object as byte array is not recommended.
The second path, that to pack the object in the Parcel and set in Intent. Then catch it using BroadcastReceiver. How about sending large object in Broadcast message?
Perhaps you can just save the image and pass through the OutputStream way? Or just save it as a static variable somewhere? I'm not an expert of Android, the main thing I want to get fast app. Thanks for your answers!
Bundle-object is only suitable for storing simple types. Translate large Bitmap-object as byte array is not recommended.
Yes, you should never transfer large data via Intent. It's not about data type, it's about size.
The second path, that to pack the object in the Parcel and set in Intent. Then catch it using BroadcastReceiver. How about sending large object in Broadcast message?
It's same thing, sending a message still requires Intent which has limitations.
Or just save it as a static variable somewhere?
This will work but this is a bad architecture. If you do this you will always have to think about that static field and be sure at all times that you are not keeping a static reference to the Bitmap you no longer need. I strongly don't recommend this.
Instead, you can store your Bitmap object to disk and then read it in your Activity. Here is an example: Save bitmap to location

Android and big extra size

I m actually facing a problem with the intent extras size. In fact I need to get a nested object containing ~2000 objects.
So, when trying to transmit this intent, I got errors telling me that the size of the object is too big.
My question is : what is the best way to manage it, without using the ugly method, corresponding to store every object in a class using the static way.
What is the best way to transmit big informations between activities.
Thanks for advance

How to pass large json string to next activity

I am sending large JSON string where records of JSON array length is 800 but currently when I start that Activity then application quits without any crash message but when I reduced the records to 100 then it works perfectly.
I am doing like below
Intent myIntent = new Intent(getActivity(),
ActivityName.class);
myIntent.putExtra("jsondata", respUserData);
getParentFragment().startActivityForResult(myIntent,
pick_plan);
getActivity().overridePendingTransition(
R.anim.lefttorightanim, R.anim.righttoleftanim);
So what it is correct way to send large JSON to next Activity ?
Thanks in advance.
Don't pass large String or Large Data directly in to intent, you have to use Application Class.
Set variables and methods in application class.
To get more information about Application Class view this answer.
Since it's probably not a global state that you pass, I advise against using the Application Class. If it is data that you use all the time you can easily store it there.
For passing a large amount of data using the provided way with putExtra() should work fine. Apparently the Bundle doesn't handle your JSONObject correctly. You can try to convert it to a String, pass this to the Intent.putExtra() and then reconstruct the JSONObject from the String. This will have some impact on the performance, but should be usable as a workaround.
You can pass values as you mentioned. It will be as a bundle so it can hold large amount of data also.
We can pass Arraylist, model classes etc using the intent.

How to send an object containing drawable objects from one android activity to another using intents?

I've gone through this: How to send an object from one Android Activity to another using Intents?
But i'm facing problem in sending images in the object to the other activity.
Please help.
Convert your Drawable to Bitmap and send it to Another Activity.
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
To send,
intent.putExtra("Bitmap", bitmap);
To Fetch,
Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
Well you can't really send images with intents since you can attach as extras to intents only Serializable objects.
But you can store images (in memory in different structures (like HashMaps, using hashmap will give you some speed optimization for searching that image)) and send notification to other activity to read from hasmap. You can add the key for the image in hashmap as string in extras attached to intent.
Or you can just cache the image and send it's name/path via intents :)
Hope this helps :)

Retrieve Image from another Intent

How can I retrieve an image from another Intent within the same application?
If I understood you correctly you can use Intent.putExtra(String, Parcelable) and Intent.getParcelableExtra(String) methods to store and load image. But it's not very fast method. And if you need to transfer a large image, you'd better put it in a static field.

Categories

Resources