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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 狂野都城

一次分布式事务管理器(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);
      }  
   }