-3

i'm developing an android app based on a list and a map.

When list is loaded, i get data from a webservice, it's the same data that i'm gonna use to add markers in the map.

How can i avoid loading data again?

Thanks.

Edit: I forgot to say that i'm using ABS tab control with two fragments, one for the list and other for the map. I would like to keep data in tab control activity and share it with fragments.

Is there a way to get the data from the parent activity inside a fragment? And for a long amount of data, is better to write content to sql?

jramillete
  • 29
  • 1
  • 5

3 Answers3

1

You can pass your data as an Intent extra and retrieve it in the other Activity:

Bundle extras = getIntent().getExtras(); 
String data;

if (extras != null) {
    data = extras.getString("key");
    //use your data
}

If your data is an object of some kind that cannot be passed via Intent extras, you could create a Singleton that extends your Application class.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

First off all your model class should be implements Serializable so u can send whole model to another activity with store data.

then after in 1st activity

intent.putExtra("model", commanModelList);

then after to get this intent in 2nd activity

commanModelList = (ArrayList<CommanModel>) getIntent().getSerializableExtra("model");

use ur commanModelList with store data.

Ketan Mehta
  • 272
  • 1
  • 12
0

You can add ArrayLists of certain types (Integer, String...) as intent extra's (e.g. public Intent putIntegerArrayListExtra (String name, ArrayList<Integer> value) on the Intent class).

If these are not suitable, you can sub-class your Application class and store your List in that, with getters / setters. Your Application object is available from all Activities using getApplication() (which you can then cast to your own application sub-type).

Neil
  • 1,821
  • 4
  • 14
  • 27