-1

I am working on a complex application which retrieve data different from websites. Unfortunately I came a cross a problem. I retrieved data from a html table which displays in a list view. This is not a problem, but when I open the activity it takes a while to retrieve everything and to display it. A solution to solve this is to put the data in SharedPreferences. In this case the data should be retrieved only once. So the data should be stored in SharedPreferences and when you reopen the activity the html data should be display without waiting. I can not figure out how to implement SharedPreferences in this case.

I hope someone is able to help me.

This is code for retrieving the data:

ListView Onderdelen = (ListView) findViewById(R.id.Onderdelen);
                    ClubkampioenschappenOnderdelenHTMLRequest clucka = new ClubkampioenschappenOnderdelenHTMLRequest(list, ClubkampioenschappenSingleenDubbelOnderdelen.this, Onderdelen);
                    clucka.execute();

The array list with all the data is called: list.

D.Bronder
  • 156
  • 1
  • 13

1 Answers1

0

//Set the values

Set<String> set = new HashSet<String>();
set.addAll(mArrayList1);
scoreEditor.putStringSet("key", set);
scoreEditor.commit();

//Retrieve the values

Set<String> set = new HashSet<String>();
set = myScores.getStringSet("key", null);

public void addTask(Task t) {
    if (null == currentTasks) {
        currentTasks = new ArrayList<task>();
    }
    currentTasks.add(t);

    //save the task list to preference
    SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();
    try {
        editor.putString(TASKS, ObjectSerializer.serialize(currentTasks));
    } catch (IOException e) {
        e.printStackTrace();
    }
    editor.commit();
}
public void onCreate() {
    super.onCreate();
    if (null == currentTasks) {
        currentTasks = new ArrayList<task>();
    }

    //      load tasks from preference
    SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE);

    try {
        currentTasks = (ArrayList<task>) ObjectSerializer.deserialize(prefs.getString(TASKS, ObjectSerializer.serialize(new ArrayList<task>())));
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94