Android, Realm: Is need every time call realm.insert(permissionOfferResponse)? -
on android client need realmurl. next steps:
- login realm object server (ros)
- create response received token
- after processing, offerresponse's realmurl property contain url of shared realm
here snippet:
public class mainapp extends multidexapplication { private void loginandconfig() { string authurl = "http://" + buildconfig.object_server_ip + ":" + buildconfig.object_server_port + "/auth"; syncuser.callback callback = new syncuser.callback() { @override public void onsuccess(syncuser user) { setpermissions(user); } @override public void onerror(objectservererror error) { string errormsg; switch (error.geterrorcode()) { case unknown_account: errormsg = "account not exists."; break; case invalid_credentials: errormsg = "user name , password not match"; break; default: errormsg = error.tostring(); } log.w(tag, "loginandconfig: onerror: result errormsg = " + errormsg); } }; synccredentials synccredentials = synccredentials.usernamepassword( buildconfig.user_name, buildconfig.password, false); syncuser.loginasync(synccredentials, authurl, callback); } private void setpermissions(final syncuser syncuser) { realm managementrealm = syncuser.getmanagementrealm(); // create response received token string offertoken = buildconfig.realm_offer_token; final permissionofferresponse permissionofferresponse = new permissionofferresponse(offertoken); // add management realm sync ros managementrealm.executetransaction(new realm.transaction() { @override public void execute(realm realm) { // call every time on start realm.insert(permissionofferresponse); } }); // after processing, offerresponse's realmurl property contain url of shared realm // wait server handle offer realmresults<permissionofferresponse> realmresultpermissionofferresponse = managementrealm.where(permissionofferresponse.class) .equalto("statuscode", 0) .findall(); realmresultpermissionofferresponse.addchangelistener(new realmchangelistener<realmresults<permissionofferresponse>>() { @override public void onchange(realmresults<permissionofferresponse> offers) { permissionofferresponse offer = offers.first(); string realmurl = offer.getrealmurl(); // success relmurl } }); } }
as can see code start on every start of application. result every time call method realm.insert(permissionofferresponse).
question: need call method realm.insert(permissionofferresponse) every time when start application?
Comments
Post a Comment