Transferring large amounts of data to Activity using putExtra ();

The application passes a large number of objects (about 150 objects after parsing the JSON ) through intent.putExtra(); Among them are serialized objects. And the process of opening a new event takes about 2 seconds ... Is there a way to speed up this process?

+2
source share
3 answers

If you just want to transfer data from one activity to another, you can simply use the static variable available from both actions. This eliminates the need for serialization and deserialization of all objects. Example:

 public class Globals { public static List<MyObject> myObjects; } 

In one action, you can set the data that you want to convey in Globals.myObjects , and receiving activity can get out of there.

Remember that this mechanism has some disadvantages (for example, when Android kills your process and restarts it later). However, this may be the least difficult way to simply transfer many objects from one activity to another.

+3
source

One suggestion could be:

Use parceable where you use serializable

Another suggestion could be:

Use something else to save / restore data. e.g. database

+2
source

I think using the Singleton class to exchange lots of temporary data between actions is a great way. It is very fast and easy.

Although it can be done using Android Parcelable , it has a storage limit that can cause this error "!!! FAILED BINDER TRANSACTION !!!"

0
source

Source: https://habr.com/ru/post/1239187/


All Articles