java - How can I store and load my Sessions as a User on Parse? -


i developing android app existing ios app, using session object store data on parse crucial me.

as creating , uploading sessions parse have no problems.

public static void syncuser() {     parseuser.getcurrentuser().fetchinbackground(new getcallback<parseobject>() {         @override         public void done(parseobject object, parseexception e) {             if (e != null) {                 log.d("", "sync error");                 e.printstacktrace();             }              if (object != null) {                 syncsessions();             }         }     }); }  private static void syncsessions() {     parsequery<parsesession> query = parsequery.getquery(parsesession.class);     query.fromlocaldatastore();     query.findinbackground(new findcallback<parsesession>() {         @override         public void done(list<parsesession> objects, parseexception e) {             (parsesession session : objects) {                 fetchsession(session, null);             }         }     }); }  public static void fetchsession(final parsesession session, final onresultcallback cb) {     session.saveinbackground(new savecallback() {         @override         public void done(parseexception e) {             if (e != null) {                 if (cb != null)                     cb.onresult(false);                 e.printstacktrace();             } else {                 if (cb != null)                     cb.onresult(true);                 parserelation<parsesession> relation = parseuser.getcurrentuser().getrelation("sessions");                 relation.add(session);                 syncuser();             }         }     }); }  public static void addnewsession(date date, string link, int successvalue) {     final parsesession session = new parsesession();     session.put("date", date);     session.put("link", link);     session.put("successvalue", successvalue);     session.pininbackground(new savecallback() {         @override         public void done(parseexception e) {             if (e != null)                 e.printstacktrace();             else {                 fetchsession(session, new parsemanager.onresultcallback() {                     @override                     public void onresult(boolean success) {                         if (success) {                             try {                                 session.unpin();                             } catch (parseexception e) {                                 e.printstacktrace();                             }                         }                     }                 });             }         }     }); }  public interface onresultcallback {     void onresult(boolean success); } 

for creating new session parameters , uploading use addnewsession() method, , displays in parse dashboard correctly, have columns fields (date, link, successvalue) , stored default session object.

but when try load them parse client, doesn't work. load them method:

public static void getsessions(final onresultcallback cb) {     parserelation<parsesession> relation = parseuser.getcurrentuser().getrelation("sessions");     parsequery<parsesession> query = relation.getquery();     query.setlimit(1000);     query.findinbackground(new findcallback<parsesession>() {         @override         public void done(list<parsesession> objects, parseexception e) {             if (e != null) {                 e.printstacktrace();                 if (cb != null)                     cb.onresult(false);             } else {                 cb.onresult(true);             }             //if (objects != null)             //use sessions         }     }); } 

i catch exception:

w/system.err: com.parse.parserequest$parserequestexception: wrong type of relation.  expecting: , received: _session w/system.err:     @ com.parse.parserequest.newpermanentexception(parserequest.java:270) 

quite similar code on ios works fine "sessions" relation. mistakes have done?

upd. have noticed exception when have allready send custom created session parse addnewsession() , trying them using getsessions(). maybe creating , sending session problem?

i found sollution. after add newly created session user relations with

parserelation<parsesession> relation = parseuser.getcurrentuser().getrelation("sessions"); relation.add(session); 

i tried save them fetchinbackground, mistake. changed syncuser() parseuser.getcurrentuser().saveinbackground() , worked.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -