-1

What is the best way to send big amount of data through intents from one activity to another. Should I split the data into small amounts and send them one by one through intents. If It takes a lot of intents such as around 1000 intents to send the entire data, will it be still efficient for android devices.

The process is sender activity will split the entire list, then send data one by one in intent body. In the receiving site, receiver activity will gather data one by one and rebuild the entire list. The problem here is If it takes too much intents (around 1000 intents) to send the entire list, will it still work in general android devices. Will it cause any performance issue?

sohan nohemy
  • 615
  • 5
  • 13

4 Answers4

1

Rather then sending big data through activities you should create a Data Controller from which you can get data. If you send data through activities you need lot of key name it will be confusing for you to track each data

class DataController{
static DataController controller;
Object data;
private DataController(){}
public static DataController getInstance(){
    if(controller==null){
        controller = new DataController();
    }
    return controller;
}

public void setData(Object data){ // SET FROM ACTIVITY 
    this.data = data;
}

public Object getData() {  // GET FROM NEXT ACTIVITY 
    return data;
}}
Vishal Gaur
  • 658
  • 6
  • 18
1

I think it's not the right track to send large data between activities directly or use singleton for that purposes:

  1. You will send every time a large amount of data - it's not good for performance.
  2. You will always keep in memory large amount of objects. That's not good too.

I think, the best way - is to use database and ORM for that.

So you can just send query to another activity and use CursorAdapter for list rendering. In this case you could show a huge amount of data, instantly "send" data between activities in two ways.

Slava
  • 1,314
  • 14
  • 28
0

Create some kind of singleton class which holds data.. in first activity set that data in that singleton class and just call second activity from first activity. onCreate() of second activity read that from singleton class.

  1. Create Singleton to hold list of data.
  2. In first activity just before calling second activity set data in that Singleton class.
  3. In second activity onCreate() read data from singleton class and set in adapter or where you want to use.
virendrao
  • 1,763
  • 2
  • 22
  • 42
  • This is not a good idea. Keep in mind that Android can kill your process at any time. If it does so when the 2nd activity is active, then when Android re-creates your process, it will attempt to restore your activity by passing Bundle data to onCreate. If your activity depends upon this singleton to restore state the singleton will have lost that state when the process was re-started. – EJK Nov 17 '15 at 05:50
0

In my case, I will send a big list to an activity and use it only once.

Database is too heavy i think, so I decide to write to cache file in json format, and pass cache file path to next activity, then read json file to list.

aotian16
  • 767
  • 1
  • 10
  • 21