android - App flow with AccountManager -


i've been struggling while app structure. , seems structure give me lot of pain in developing of other features. before going further i'd have advice , see if i'm doing wrong here.

my app's purpose connect server, use accountmanager mechanism create account on device , store token supposed used request data server. in creation of account, fine. (it works device settings -> add account)

it goes :

mainactivity activity that, when launch app, check if have account. if have account, token in static variable every fragment in mainactivity can access it. (supposed work doesn't) else, create intent loginactivity create account on device. problem fragments can't token because, i'm recovering token in thread using accountmanager.getauthtoken(), fragments created before token recovered. , therefore can't request data server.

which led me think app structure might not good. thinking, "what if so?" :

  • the user launches app
  • mainactivity act bootstrap check account , token if there's account on device not generate kind of view current version.
  • mainactivity either redirect loginactivity or contentactivity (let's call way, activity that's supposed use token populate data in listviews)

that way lets me think mainactivity have token pass i'm not sure it's ideal in terms of ux. (gotta wait token before accessing content). i'm open every suggestion @ point since i'm stuck.

thanks !

update 1:

it's more of login/registration app logic handling accountmanager. i've managed make them work struggle "best practice" app logic structure don't run many other problems because of (as don't have time). need diagram or show me "best practice" example make app works way explained above. ran problem because when start mainactivity checks account , if not launches loginactivity if press back, can see mainactivity (unfilled).

more of general practice you're using:

general practice

this structure acceptable , normal flow of server-dependent apps. prefer model logging is option content not require logging in. whenever action requires login triggered, user shown login. however, model should work fine.

i see problems

  1. i ran problem because when start mainactivity checks account , if not launches loginactivity if press back, can see mainactivity (unfilled).

    this issue can solved invisible dispatch activity launches mainactivity or loginactivity based on status of current user. in diagram, finish() dispatch activity after decision. loginactivity responsible of relaunching dispatchactivity redecide on next step. generally, not override onbackpressed of loginactivity launch dispatch, launch dispatch in case of successful login.

    however, if you've decided show content in activity if user not logged in, can use onactivityresult refresh content of mainactivity after login request.

  2. the problem fragments can't token because, i'm recovering token in thread using accountmanager.getauthtoken(), fragments created before token recovered.

    this problem normal. if activities/fragments created when processing login request, must able inform these. basically, if fragments not show "unauthenticated" content, should not face problem because should not create these fragments until logged in.

    however, again, if you've decided show content in activities/fragments when user not logged in, have inform these running components status change. 1 way implement onresume in activities checks if user logged in , suitable changes. way use local broadcast inform running activities/fragments state has changed:

    broadcastreceiver mreciever = new broadcastreceiver() {     public void onreceive(context context, intent intent) {             //do whatever want //check state     } };  public void oncreate(bundle state) {    //bla bla    //bla bla    localbroadcastmanager.getinstance(mcontext).registerreceiver(mreciever, new intentfilter("your_package_name.login_state_changed")); } 

    whenever state changes, send broadcast:

    intent intent = new intent("your_package_name.login_state_changed"); localbroadcastmanager.getinstance(mcontext).sendbroadcast(intent); 

of course, can turn out case-specific. example, if check touch app on google play, notice i've created dispatch screen visible regardless of user's login state , asked user login if enters activity requires login. in case, activity requires login should implement onactivityresult accordingly , update ui if user logged in or finish if user didn't. on other hand, psst app on google play uses splash screen decide whether go login screen or main screen depending on user's state.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -