android如果用户没有登录,就跳到登录页面应该这个逻辑应该在activity的什么地方实现比较好?
2 回答
波斯汪
TA贡献1811条经验 获得超4个赞
两种处理方式吧:@ShawnXiaFei所说的写到BaseActivity里publicclassBaseActivityextendsAppCompatActivity{publicbooleanacquireAuthorization(){if(!isAuthorized()){if(!onAcquireAuthorization()){finish();returnfalse;}}returntrue;}publicbooleanisAuthorized(){returntrue;}publicbooleanonAcquireAuthorization(){returnfalse;}}publicclassAppActivityextendsBaseActivity{@OverridepublicbooleanisAuthorized(){//TODOreturnsuper.isAuthorized();}@OverridepublicbooleanonAcquireAuthorization(){//TODOreturnsuper.onAcquireAuthorization();}}publicclassMainActivityextendsAppActivity{@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);if(acquireAuthorization()){//TODO...}}}
添加回答
举报
0/150
提交
取消