parse.com - Updating Parse User information locally without having to log out and log in again in Android -
i have app uses parse backend server. user information stored , can changed via edit profile activity. problem having this:
1. information gets changed on parse server correctly. 2. information doesn't updated on app unless log out, log in forces user information retrieved parse. 3. don't want force user log out/log in each time change information. there way refresh current parse user information way?
yes, can through few options. first, can add swiperefreshlayout can surround main layout , users can swipe down refresh content. mean override onrefreshlistener's onrefresh method call fetch() on objects parse wanted refresh, , update ui (notifydatasetchanged incase of listview/recyclerview/etc).
another option, can provide refresh button somewhere in user interface, actionbar. same process swiperefreshlayout, right make click listener instead calls similar method defined in onrefresh method swiperefreshlayout.
rememeber preform parseobject fetch calls in asyncthread, , upon successful fetch update ui. changing information on parse via edit profile activity, , updates on server , fixes when logout / log in because fetching again when logged in.
since updating information in 1 activity, , returning another, pass information via intent returning updates user interface, (while @ same time backend updated information). make editprofileactivity called via intent startactivityforresult mainactivity, , pass information via bundle , intent. ex below:
intent intent = new intent(); bundle extras = new bundle(); extras.putstring("name", nameedit.gettext().tostring()); extras.putstring("email", emailedit.gettext().tostring()); intent.putextras(extras); setresult(result_ok, intent); //assuming edit went okay finish();
then in mainactivity:
protected void onactivityresult(int requestcode, int resultcode, intent data) { if(resultcode == result_ok && data != null){ bundle extras = data.getextras(); //deal getting extras here } }
the above solution assume know extras being passed every time, , may not preferred since user's may or may not edit fields, or fields might information pass. in case, fetch() option.
Comments
Post a Comment