sqlite - ActiveAndroid - How to save data into Android database -


i have android app in i'm getting data api. need save data api activeandroid table.

so i've got stuck on part.

here table partners(active android):

@table(name = "partners") public class partners extends model {      @column(name = "name")     public string name;      public partners() {}      public partners(string name) {         this.name = name;     } } 

this pojo model:

public class partner {      @expose     @column(name = "name")     private list<string> name;       public list<string> getname() {         return name;     }     public void setname(list<string> name) {         this.name = name;     } } 

and here part of code i'm getting data , trying save activeandroid table:

public class downloadmain extends fragment implements callback<partner> {      private static final string tag = downloadmain.class.getsimplename();      private button dloadpartners;     private call callpartners;      public downloadmain() {}      public downloadmain newinstance() { return new downloadmain(); }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view view = inflater.inflate(r.layout.download_main, container, false);          dloadpartners = (button) view.findviewbyid(r.id.downloadpartners);         dloadpartners.setonclicklistener(btnlistener);          callpartners = apihelper.getapiservice().getpartners();          return view;     }      button.onclicklistener btnlistener = (new button.onclicklistener() {         @override         public void onclick(view v) {             callpartners.clone().enqueue(downloadmain.this);             insertpartners();         }     });      @override     public void onresponse(call call, response response) {          if(response.body() == null) {             try {                 response.errorbody().string();             } catch (ioexception e) {                 e.printstacktrace();             }             toast.maketext(getactivity(), "no partners!", toast.length_short).show();         } else {             list<string> partners = (list<string>) response.body();             log.d(tag, "number of partners received: " + partners.size());             toast.maketext(getactivity(), "partners downloaded!", toast.length_short).show();         }     }     @override     public void onfailure(call call, throwable t) {     }      private void insertpartners() {         activeandroid.begintransaction();         try {             (int = 0; < 100; i++) {                 partner partner = new partner();                 partner.getname();                 //partner.save();             }             activeandroid.settransactionsuccessful();         } {             activeandroid.endtransaction();         }     } } 

the problem how save data api table, need few tips , advice how that.

question: need tips how save data web retrofit activeandroid table?

please check old weather app project, i'f used activeandroid.

here's 1 of saving database methods:

public void savecitydatatodatabase(forecast forecast) {     activeandroid.begintransaction();     try {         if (weatherapplication.getcitylist().size() > 0) {             new delete().from(city.class).execute();         }         forecast.getcity().getcoord().save();         forecast.getcity().save();         activeandroid.settransactionsuccessful();     } {         activeandroid.endtransaction();     }     log.d("database", "weatherapplication: " + weatherapplication.getcitylist()); } } 

from: https://github.com/piotrek1543/localweather/blob/master/app/src/main/java/com/piotr/localweather/repositories/weatherdatabaserepository.java

with activeandroid easy save objects weather or wind, purposes need use typeserializer. in example use deserialize , save list<string>.

as may notice github page: https://github.com/pardom/activeandroid libary not maintained more 2 years, can deprecated , not use fresh projects. may have many bugs. me, implementation of lib pretty painful.

instead of activeandroid, recommend use realm, greendao or ormlite library store data.

hope help


Comments