facebook - How to handle Multiple Social Media Logins and sessions Flow on Android? -
i have created android app has navigation drawer fragments.
i started social media integrations, facebook, twitter , google plus. using official respective sdk's.
not social media sessions , calls acquire data made in following activities:
mainactivity: if of sessions lost or revoked, needs redirectloginactivity. done during activity lifecycle methods.loginactivity: permission granted , redirects main after successnavigationdrawerfragment: navigation drawer, use display user's profile image, name , email address.
in these 3 classes making calls respective sdk methods , managing sessions there lot of code duplication.
also 3 sdk's have different ways of providing authentication.
- facebook: uses
uilifecyclehelperimplemented on standard lifecycle functions of activity. - google plus: have implement
googleplaystore callbacks in activity , creategoogleapiclienton activities. - twitter: has less of "taking on app" attitude , uses retrofit in same manner of usual rest api call on android: retrofit. have give permissions on every login.
so of these functions handling different social media logins included in required activities making application code bulky , hard manage.
do have suggestions on how abstract these auth methods maintainable solutions makes manging sessions easier? better off have separate activities based on login used?
i have done several times , best approach can recommend is:
- extract part of integration want add. sharing, want let user start session, need kind of api keys.
- once done first step, can extract abstraction layer methods common social platforms (there common function).
- generate factory every platform
facebookfactoryortwitterfactorycapable generate prepared objects given task. imagine want login, ask concrete factorylogintask, expose common actionsrequestoauthtoken,getsession, etc. if reason there cannot abstracted, can downcast knowing not break application. - you can generate feel more confortable second abstraction layer using facade pattern, constructed via
contextobject (some networks facebook invasive , need know many things), deciding social network want work onenum.
here mock example on how code can like:
socialfacade facade = socialfacade.getinstance(); socialsession session = facade.getsession(network.twitter); string token = session.requesttoken(apiid); facade.getshare(network.twitter).sharepost(apiid, message); of cours can use kind of third party library, approach use when nothing suits needs.
Comments
Post a Comment