惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
IT之家
IT之家
腾讯CDC
博客园 - 【当耐特】
博客园 - 聂微东
月光博客
月光博客
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
博客园 - 叶小钗
S
Security @ Cisco Blogs
雷峰网
雷峰网
N
News and Events Feed by Topic
Attack and Defense Labs
Attack and Defense Labs
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
Lohrmann on Cybersecurity
Project Zero
Project Zero
www.infosecurity-magazine.com
www.infosecurity-magazine.com
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
The Last Watchdog
The Last Watchdog
Apple Machine Learning Research
Apple Machine Learning Research
W
WeLiveSecurity
C
Cisco Blogs
T
Tenable Blog
Schneier on Security
Schneier on Security
爱范儿
爱范儿
美团技术团队
V2EX - 技术
V2EX - 技术
V
V2EX
Google Online Security Blog
Google Online Security Blog
Last Week in AI
Last Week in AI
Security Archives - TechRepublic
Security Archives - TechRepublic
The Hacker News
The Hacker News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
博客园_首页
H
Hacker News: Front Page
量子位
N
News | PayPal Newsroom
大猫的无限游戏
大猫的无限游戏

博客园 - 狂野都城

一次分布式事务管理器(MSDTC)的事务处理异常的排错 FMS3.5 的logs 日志目录配置 C#磁盘大小管理操作类 C#建立IIS虚拟目录站点 IO操作类 同步和异步方式获取网页源代码! 判断一幅图片是否是黑色,灰度直方图 winform窗体置前 关于FMS服务端数据流发布 如何配置FMS边缘服务器 Windows服务“允许服务与桌面交互”的使用和修改方法 招聘:Flash视频开发程序员(网络多媒体应用) 招聘:windows mobile 手机应用软件的开发 Word 2007 里头鼠标失效(滚轮除外) ,困扰多天! 终止线程 Response.End 在Asp.net 里面的正确使用 Access 中查询TOP语句的奇怪问题??? 一道小学数学题... net常用代码 (收藏) 在VS2005 开发中使用Codesmith 和NetTiers 模版开发相关
后台线程处理
狂野都城 · 2011-07-25 · via 博客园 - 狂野都城

/*
  * 处理后台线程
  */
 public void doBackGround(){
 

  if(!CurInfo.Info.ai_logined){
   //Toast.makeText( this, "正在获取数据...", Toast.LENGTH_SHORT ).show();
   
   /*
   // 这里这个参数指定的是线程的名字 
         HandlerThread handlerThread = new HandlerThread("MyHandler"); 
         // 在使用HandlerThread的getLooper()方法之前,必须先调用该类的start(); 
         handlerThread.start();// 启动这个线程 
         //handlerThread.getLooper();
         MyHandler myHandler = new MyHandler(handlerThread.getLooper());
        
         */
   
   
         /*
         // 这里这个obtainMessage()方法返回 
         Message msg = myHandler.obtainMessage(); 
         // 将msg发送到目标对象,所谓的目标对象,就是生成该msg对象的handler对象 
         Bundle b = new Bundle(); 
         b.putInt("age", 20); 
         b.putString("name", "Jhon"); 
         msg.setData(b); 
         msg.sendToTarget(); 
         */
        
         new MyAsyncTask().doInBackground();
  }
 }

/*
  * 线程处理
  */
 class MyHandler extends Handler { 
        public MyHandler() {
         
        } 
 
        public MyHandler(Looper looper) { 
            super(looper);
            // 这里处理任务
           
            String result = AIData.aiInfo.loginHouse("999", "888");            
            if(result != "error"){             
             AIData.aiInfo.GetDeviceList(3); 
             CurInfo.Info.ai_SeeionId = result;
    CurInfo.Info.ai_logined = true;
            }
           
           
        } 
 
        @Override 
        public void handleMessage(Message msg) { 
            // 这里我们只做了简单的输出 
         /*
            Bundle b = msg.getData(); 
            int age = b.getInt("age"); 
            String name = b.getString("name"); 
            System.out.println("age is " + age + ", name is" + name); 
            System.out.println("Handler--->" + Thread.currentThread().getId()); 
            System.out.println("handlerMessage");
            */ 
        } 
    } 
 /*
  * 线程处理
  */
 private class MyAsyncTask extends AsyncTask<Void, Void, Void> {
   @Override
      protected Void doInBackground(Void... params) {
          //耗时操作,后台线程处理
          try {
              //Thread.sleep(4*1000);
             
              String result = AIData.aiInfo.loginHouse("999", "888");            
              if(result != "error"){             
               AIData.aiInfo.GetDeviceList(3); 
               CurInfo.Info.ai_SeeionId = result;
      CurInfo.Info.ai_logined = true;
              }             
             
          } catch (Exception  e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          return null;
      }
      @Override
      protected void onPostExecute(Void result) {
          //作UI线程的修改。
          //progressDialog.dismiss();
          super.onPostExecute(result);
      }  
   }