在Android 中判断当前的Thread是否是UI Thread 的方法:

  1.

if (Looper.myLooper() == Looper.getMainLooper()) {
// Current thread is the UI/Main thread
}

2.

if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
// Current thread is the UI/Main thread
}

参考如下文章:其中还讲到了  runOnUiThread()  方法的用法。

http://codetheory.in/checkdetect-whether-current-thread-uimain-thread-android/

http://lak4cyut.blogspot.jp/2011/03/android-tip-activityrunonuithread.html

Android 判断当前thread 是否是UI thread的更多相关文章

  1. Android Non-UI to UI Thread Communications(Part 2 of 5)

    Original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-2-of-5/ his i ...

  2. Android Non-UI to UI Thread Communications(Part 3 of 5)

    Original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-3-of-5/ Conti ...

  3. Android Non-UI to UI Thread Communications(Part 1 of 5)

    original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-1-of-5/ ANDRO ...

  4. android 进程/线程管理(三)----Thread,Looper / HandlerThread / IntentService

    Thread,Looper的组合是非常常见的组合方式. Looper可以是和线程绑定的,或者是main looper的一个引用. 下面看看具体app层的使用. 首先定义thread: package ...

  5. Android开发笔记之:Handler Runnable与Thread的区别详解

    在java中可有两种方式实现多线程,一种是继承Thread类,一种是实现Runnable接口:Thread类是在java.lang包中定义的.一 个类只要继承了Thread类同时覆写了本类中的run( ...

  6. Sub Thread to update main Thread (UI) 2

    Sub Thread to update main Thread (UI)  2 Handler.post(somethread); Handler.sendMessage("Msg&quo ...

  7. Sub Thread to update main Thread (UI)

    Sub Thread to update main Thread (UI) main Thread :   A  has Hander.HandleMessage() to process the & ...

  8. Android中使用异步线程更新UI视图的几种方法

    在Android中子线程是不能更新ui的. 所以我们要通过其他方式来动态改变ui视图, 1.runOnUiThreadactivity提供的一个轻量级更新ui的方法,在Fragment需要使用的时候要 ...

  9. Android子线程真的不能更新UI么

    Android单线程模型是这样描述的: Android UI操作并不是线程安全的,并且这些操作必须在UI线程执行 如果在其它线程访问UI线程,Android提供了以下的方式: Activity.run ...

随机推荐

  1. Xcode常见问题

    今天真机测试的时候,突然出现了这个错误:  not have an architecture that “Administrator”的 iPhone (3) can execute. 原因是我刚刚修 ...

  2. JS学习笔记(1)--sort排序

    sort() 方法用于对数组的元素进行排序. 请注意,数组在原数组上进行排序,不生成副本. 说明 如果调用该方法时没有使用参数,将按字母顺序对数组中的元素进行排序,说得更精确点,是按照字符编码的顺序进 ...

  3. 跟着百度学PHP[11]-PHP当中的异常处理

    首先要说一下常见的三种错误: 1.语法错误 2.运行错误 3.逻辑错误 00x1 错误报告及错误级别 PHP的错误分为三个等级 1.注意(notice)   没有变量a 2.警告(warning) 没 ...

  4. Extjs,实现树形结构的总结

    工作总结,用extjs.mybatis.springMVC实现树形显示班级 前台extjs实现树形代码如下: xtype : 'combotree', fieldLabel : '部门名称', nam ...

  5. am335x omap serial 驱动分析

    am335x 自身的 uart 驱动集成在 kernel 的 arch/arm/mach-omap2/ 里面. 文件是 arch/arm/mach-omap2/serial.c // 看到最底部 om ...

  6. [shell]C语言调用shell脚本接口

    Use popen if you want to run a shell command and want the parent process to be able to talk to the c ...

  7. 数据库 Proc编程二

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...

  8. Softmax回归推导过程

    http://www.cnblogs.com/Deep-Learning/p/7073744.html http://www.cnblogs.com/lutingting/p/4768882.html ...

  9. poj3301--Texas Trip(最小正方形覆盖)

    题目链接:点击打开链接 题目大意:给出n个点的坐标.如今要求一个正方形,全然包围n个点.而且正方形面积最小,求最小的正方形面积. 表示不能理解为什么面积随着角度的变化是一个单峰的函数,等待大牛告诉一下 ...

  10. 自己开发iOS版按键精灵--TTouch

    利用闲余时间,把之前的按键录制和播放整理了一些,开发了一个iOS版按键录制.播放的越狱APP,类似按键精灵.触动精灵等按键类的基本功能.脚本采用lua语法格式,可直接执行lua脚本,通过lua和obj ...