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 redirect loginactivity. done during activity lifecycle methods.

  • loginactivity : permission granted , redirects main after success

  • navigationdrawerfragment : 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 uilifecyclehelper implemented on standard lifecycle functions of activity.
  • google plus: have implement googleplay store callbacks in activity , create googleapiclient on 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 facebookfactory or twitterfactory capable generate prepared objects given task. imagine want login, ask concrete factory logintask , expose common actions requestoauthtoken, 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 context object (some networks facebook invasive , need know many things), deciding social network want work on enum.

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

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -