android - How to stop an activity from starting while checking if a user is logged in? -
i trying achieve following when user starts app:
1- if user not logged in show login screen. 2- if user created account , there valid token show start screen.
to end have implemented custom authenticator based on tutorial found here http://www.udinic.com/.
the code works, issue shows current activity ui briefly switches add account ui provided accountauthenticator. how can fixed this?
this code:
@override public void onstart(){ super.onstart(); gettokenforaccountcreateifneeded(accountgeneral.account_type, accountgeneral.authtoken_type_full_access); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); maccountmanager = accountmanager.get(this); } /** * auth token account. * if not exist - add , return auth token. * if 1 exist - return auth token. * if more 1 exists - show picker , return select account's auth token. * @param accounttype * @param authtokentype */ private void gettokenforaccountcreateifneeded(string accounttype, string authtokentype) { final accountmanagerfuture<bundle> future = maccountmanager.getauthtokenbyfeatures(accounttype, authtokentype, null, this, null, null, new accountmanagercallback<bundle>() { @override public void run(accountmanagerfuture<bundle> future) { bundle bnd = null; try { bnd = future.getresult(); final string authtoken = bnd.getstring(accountmanager.key_authtoken); showmessage(((authtoken != null) ? "success!\ntoken: " + authtoken : "fail")); } catch (exception e) { e.printstacktrace(); showmessage(e.getmessage()); } } } , null); }
force users login @ start of app. have implemented custom authenticator based on tutorial found here http://www.udinic.com/.
since authentication method asynchronous, can't prevent ui showing. implement router/splashscreen activity
checks authentication status , starts either login activity
or actual activity
user sees if he's logged in. make sure set router activity
nohistory
in manifest.
if want keep in single activity
, should have full-screen loading indicator in layout lays on top of ui , fades out once have figured out layout show.
Comments
Post a Comment