1

I want to save a List<HashMap<String,String>> to my small db. How to achieve it.. I want to use this list in many activities of my app. Is there any other possible way to access this particular list as it is in my other activities.

Vinay
  • 6,891
  • 4
  • 32
  • 50
Niko
  • 1,367
  • 1
  • 13
  • 37
  • 1
    Convert it as `jsonstring` and save it in db – Pragnani May 17 '13 at 11:40
  • You could also try parsing it to XML with [XStream](http://xstream.codehaus.org/). It has a built in [MapConverter](http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/converters/collections/MapConverter.html). – James May 17 '13 at 11:42
  • check: [How can I store an ArrayList> in SharedPreferences?](http://stackoverflow.com/questions/15629355/how-can-i-store-an-arraylisthashmapstring-string-in-sharedpreferences) – Paresh Mayani May 17 '13 at 11:43
  • I have already checked this http://www.verious.com/qa/how-can-i-store-an-array-list-lt-hash-map-lt-string-string-gt-gt-in-shared-preferences/ – Niko May 17 '13 at 11:46

1 Answers1

0

You can use "ContentValues" to create the entries

ContentValues content = new ContentValues;

and then at some point you populate a table with it :

_sqlDataBase.insert(tableName, null, content);

With this you just have to build the ContentValue with your List of HashMap and then populate a table.

It's good to do that only the first time your application is launched, and then only for refresh operation. When your SQLite database is populated you usually only want to access data. You can store those data in the Application instance of your application.

public class SomeApplication extends Application {

public List<HashMap<String,String>> datas;

@Override
    public void onCreate() {

        super.onCreate();

    }
}

Declare it in your manifest and then you can access it in every Activity (this.getApplication()) and Fragment (with getActivity().getApplication())

...

 <application
        android:name="com.package.app.SomeApplication"

...

Hope it helps

An-droid
  • 6,433
  • 9
  • 48
  • 93