android initialize two times in two different activities -


not able initialize parse 2 times in 2 activity call data 2 classes of parse , put them in different list views. @ second time when opening contact activity action item app stops

main activity.java

public class mainactivity extends actionbaractivity {      private countryadapter madapter;         @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          parse.initialize(this, "0fgkgokshcbpqspy**********", "f1hz9w4c***********");          parseobject.registersubclass(country.class);           madapter = new countryadapter(this, new arraylist<country>());          listview mlistview = (listview) findviewbyid(r.id.country_list);         mlistview.setadapter(madapter);          updatedata();     }      @override     public boolean oncreateoptionsmenu(menu menu) {          getmenuinflater().inflate(r.menu.menu_main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         int id = item.getitemid();          if (id == r.id.action_contact) {              intent = new intent(this, contactactivity.class);              startactivity(i);             return true;         }          return super.onoptionsitemselected(item);     }      public void updatedata() {         parsequery<country> query = parsequery.getquery(country.class);          query.setcachepolicy(parsequery.cachepolicy.cache_then_network);         query.findinbackground(new findcallback<country>() {             @override             public void done(list<country> countrys, com.parse.parseexception e) {                  if (countrys != null) {                     madapter.clear();                     (int = 0; < countrys.size(); i++) {                         madapter.add(countrys.get(i));                     }                 }             }         });        } } 

contactactivity.java

public class contactactivity extends actionbaractivity {     private contactadapter madapter;      @override     protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_contact);          parse.initialize(this, "0fgkgoksh********************", "f1hz9w4cko2ag*******************");          parseobject.registersubclass(contact.class);           madapter = new contactadapter(this, new arraylist<contact>());          listview mlistview = (listview) findviewbyid(r.id.contact_list);         mlistview.setadapter(madapter);           updatedata();     }      @override     public boolean oncreateoptionsmenu(menu menu) {          getmenuinflater().inflate(r.menu.menu_contact, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {          return super.onoptionsitemselected(item);     }      public void updatedata() {         parsequery<contact> query = parsequery.getquery(contact.class);          query.setcachepolicy(parsequery.cachepolicy.cache_then_network);         query.findinbackground(new findcallback<contact>() {             @override             public void done(list<contact> contact, com.parse.parseexception e) {                  if (contact != null) {                     madapter.clear();                     (int = 0; < contact.size(); i++) {                         madapter.add(contact.get(i));                     }                 }             }         });      } } 

you should initialize parse in class extends application class this

public class myapplication extends application {      @override     public void oncreate() {         super.oncreate();         parse.initialize(this, "xxxxxxxxxxxx", "xxxxxxxxx");     } } 

and put application class name in manifest file like

<application     android:name=".myapplication" /> 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -