Foursquare 源码研究之------登录续
来源:互联网 发布:公共卫生学mac 编辑:程序博客网 时间:2024/06/04 19:27
原文地址:http://derekzhan.iteye.com/blog/834428
上次说到了登录回调方法onPostExecute,此方法是AsyncTask的方法,当doInBackground方法执行完后调用此方法来处理返回结果.在onPostExecute中主要根据登录结果来做不同的事情,登录成功://发送登录广播
- sendBroadcast(new Intent(Foursquared.INTENT_ACTION_LOGGED_IN));
sendBroadcast(new Intent(Foursquared.INTENT_ACTION_LOGGED_IN));
此广播的订阅时在Foursquared类中实现的,首先看此类Foursquared extends Application,Application是android项目运行的一个全局的状态 "Base class for those who need to maintain global application state". 可以在Manifest.xml中指定你自定义的application. 在此类中有一个LoggedInOutBroadcastReceiver 来处理接收到的广播,然后广播发送一个message.此message对应有一个TaskHandler.在foursquare中他使用了
- mTaskThread = new HandlerThread(TAG + "-AsyncThread");
- mTaskThread.start();
- mTaskHandler = new TaskHandler(mTaskThread.getLooper());
mTaskThread = new HandlerThread(TAG + "-AsyncThread");mTaskThread.start();mTaskHandler = new TaskHandler(mTaskThread.getLooper());
上面的方式来创建Handler. 是为了让handler运行在新的线程中. 接下来看handleMessage方法对msg的处理.第一个switch case语句是MESSAGE_UPDATE_USER, 更新一下用户的信息.同时保存在SharedPreferenses中.
接下来开始一个更新UI的Service foursquared.requestStartService(); 主要调用FoursquaredService类的updateWidgets方法来更新widget.也是在Foursquared类中来进行更新,看handleMessage():
- case MESSAGE_START_SERVICE: //updateWidgets更新组件
- Intent serviceIntent = new Intent(Foursquared.this, FoursquaredService.class);
- serviceIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
- startService(serviceIntent);
- return;
case MESSAGE_START_SERVICE: //updateWidgets更新组件 Intent serviceIntent = new Intent(Foursquared.this, FoursquaredService.class); serviceIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); startService(serviceIntent); return;
启动一个FoursquaredService.
接下来返回到主界面
- // Launch the main activity to let the user do anything.
- Intent intent = new Intent(LoginActivity.this, MainActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
// Launch the main activity to let the user do anything. Intent intent = new Intent(LoginActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);
如果登录失败:
- sendBroadcast(new Intent(Foursquared.INTENT_ACTION_LOGGED_OUT));//发送登出广播.
- NotificationsUtil.ToastReasonForFailure(LoginActivity.this, mReason);//根据不同的exception来提示失败信息
sendBroadcast(new Intent(Foursquared.INTENT_ACTION_LOGGED_OUT));//发送登出广播.NotificationsUtil.ToastReasonForFailure(LoginActivity.this, mReason);//根据不同的exception来提示失败信息
最后关闭进度条dismissProgressDialog().
到这里登录就结束了.写的比较乱.呵呵.
- Foursquare 源码研究之------登录续
- Foursquare 源码研究之---------用户登录
- OAuth2.0实践之foursquare客户端登录
- Shiro源码研究之登录与登出
- Foursquare
- 【Hadoop源码研究】之Configuration
- elasticsearch源码研究之启动
- MyBatis源码研究之$和#
- Mybatis源码研究之DynamicContext
- Mybatis源码研究之XMLScriptBuilder
- Mybatis源码研究之BoundSql
- Mybatis源码研究之SqlSource
- Mybatis源码研究之Logger
- druid源码研究之Filter
- SpringBoot源码研究之Start
- Spring源码研究之@Configuration
- Shiro源码研究之ShiroFilterFactoryBean
- bbs源码分析 之 jive源码研究
- C/C++中float和double的存储结构
- phpmyadmin配置信息
- eclipse中tomcat发布项目配置
- Foursquare 源码研究之---------用户登录
- java泛型
- Foursquare 源码研究之------登录续
- C/C++中float和double的存储结构
- OS X: 实用脚本程序系列-15
- Fixedsys控的福音! Vs2010有福了!
- 《软件工程》笔记
- 类加载器作用
- 学习PHP的事前准备
- 数据结构 - 有两个链表,第一个升序,第二个降序,合并为一个升序链表(C++)
- 2012-07-05