当前位置: 首页 > news >正文

企业建立网站需要什么条件做海报的话网站

企业建立网站需要什么条件,做海报的话网站,东莞型网站建设,广州手机app开发本节向你展示如何在任务中发送数据给UI线程里的对象#xff0c;这个特性允许你在后台线程工作#xff0c;完了在UI线程展示结果。在UI线程定义一个HandlerHandler是Android系统线程管理框架里的一部分。一个Handler对象接收消息#xff0c;并且运行代码来处理消息。正常情况…本节向你展示如何在任务中发送数据给UI线程里的对象这个特性允许你在后台线程工作完了在UI线程展示结果。在UI线程定义一个HandlerHandler是Android系统线程管理框架里的一部分。一个Handler对象接收消息并且运行代码来处理消息。正常情况下你为新线程创建Handler,但你也可以为已有的线程创建一个Handler.当你连接Handler到UI线程时处理消息的代码会在UI线程上运行.在创建线程池的类的构造器里实例化Handler对象保存在全局变量里。用Handler(Looper)方法实例化连接到UI线程构造方法使用Looper对象也是Android系统线程管理框架里的一部分.Looper类有一个静态方法getMainLooper()可以获取UI线程的Looper对象。如:private PhotoManager() {...// Defines a Handler object thats attached to the UI threadmHandler new Handler(Looper.getMainLooper()) {...在Handler里覆盖handleMessage()。Android系统会在Handler管理的线程收到新消息时调用该方法。一个指定线程的所有Handler对象都会收到相同的消息。/** handleMessage() defines the operations to perform when* the Handler receives a new Message to process.*/Overridepublic void handleMessage(Message inputMessage) {// Gets the image task from the incoming Message object.PhotoTask photoTask (PhotoTask) inputMessage.obj;...}...}}从任务里移动数据到UI线程要从后台线程的任务里移动数据到UI线程的对象先保存引用到数据和任务对象的UI对象里接下来把任务对象和状态码传给Handler对象。在这个对象里发送一个包含状态 和任务对象的消息给Handler.因为Handler在UI线程上运行它可以移动数据给UI对象。在任务对象里存储数据如这是一个Runnable,运行在后台线程它解析Bitmap,并保存到它的父对象。Runnable同时保存状态码DECODE_STATE_COMPLETED。// A class that decodes photo files into Bitmapsclass PhotoDecodeRunnable implements Runnable {...PhotoDecodeRunnable(PhotoTask downloadTask) {mPhotoTask downloadTask;}...// Gets the downloaded byte arraybyte[] imageBuffer mPhotoTask.getByteBuffer();...// Runs the code for this taskpublic void run() {...// Tries to decode the image bufferreturnBitmap BitmapFactory.decodeByteArray(imageBuffer,0,imageBuffer.length,bitmapOptions);...// Sets the ImageView BitmapmPhotoTask.setImage(returnBitmap);// Reports a status of completedmPhotoTask.handleDecodeState(DECODE_STATE_COMPLETED);...}...}...PhotoTask还包含一个ImageView引用用来显示Bitmap.尽管引用Bitmap和ImageView是在同一个对象里但因为不是在UI线程你不能直接让ImageView显示Bitmap.沿对象层次逐级发送状态PhotoTask持有解码的数据和显示数据的View对象的引用它从PhotoDecodeRunnable接收到状态码并且沿着线程池里引用的对象和Handler实例传送。public class PhotoTask {...// Gets a handle to the object that creates the thread poolssPhotoManager PhotoManager.getInstance();...public void handleDecodeState(int state) {int outState;// Converts the decode state to the overall state.switch(state) {case PhotoDecodeRunnable.DECODE_STATE_COMPLETED:outState PhotoManager.TASK_COMPLETE;break;...}...// Calls the generalized state methodhandleState(outState);}...// Passes the state to PhotoManagervoid handleState(int state) {/** Passes a handle to this task and the* current state to the class that created* the thread pools*/sPhotoManager.handleState(this, state);}...}移动数据到UIPhotoManager从PhotoTask对象接收到状态码和PhotoTask对象的句柄。因为状态是TASK_COMPLETE创建一个包含状态和任务对象的Message发送给Handler。public class PhotoManager {...// Handle status messages from taskspublic void handleState(PhotoTask photoTask, int state) {switch (state) {...// The task finished downloading and decoding the imagecase TASK_COMPLETE:/** Creates a message for the Handler* with the state and the task object*/Message completeMessage mHandler.obtainMessage(state, photoTask);completeMessage.sendToTarget();break;...}...}最终Handler.handleMessage()为每个进来的Message检查状态码。如果状态码是TASK_COMPLETE任务就是完成了Message里的PhotoTask对象包含Bitmap和ImageView.因为Handler.handleMessage()运行在UI线程它可以安全地为ImageView设置Bitmap.
http://www.pierceye.com/news/521480/

相关文章:

  • 大宇网络做网站怎么样app制作器下载软件
  • 四川建行网站做网站公司职务
  • 广州定制网站设计图标设计免费 logo
  • 十大网站有哪些网站建设 模板
  • 网站流量一直下降中国十大品牌网
  • 同学录网站开发的背景域名注册网站免费
  • 旅游电子商务网站建设规划书温州网站建设策划方案
  • 国家住房建设部网站域名查询官方网站
  • app开发 网站开发统称宁波seo推广咨询
  • 专门做书单的网站网络营销策划方案的设计
  • 网站建设推广合同自己建设网站需要花多少钱
  • 深圳网站建设电话哈尔滨建设网站官网
  • 上海网站建设网页制作培训做网站做论坛赚钱吗
  • 为网站做电影花絮哈尔滨互联网公司
  • 哈尔滨微网站建设公司做网站被骗该咋样做
  • 做翻译 英文网站dede网站版权信息
  • 梅江区住房和城乡建设局官方网站品牌设计帮
  • 单页网站cms建设通会员多少一年
  • app营销型网站的特点公司建设网站怎么作账
  • 有免费做海报的网站吗制作表情包
  • 网站建设的平台做微课的网站
  • 有没有专门做美食海报的网站郑州网站建设搜q.479185700
  • 公司网站宣传做网站时版权怎么写
  • 可以在哪些网站 app做推广的建站官网模板
  • 网站建设标书卧龙区建网站
  • 东莞做网站软件嘉兴网站制作价格
  • 学网站建设 去那里合肥专业网站优化
  • 个人网站 备案 广告建设国际网站
  • 苏州建站推广公司做网站费用怎么记分录
  • 做的比较好的家具网站首页在win10下建设网站