在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. spring boot热部署pom.xml配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  2. CodeForces 2A Winner

    Winner Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. ural1517后缀数组

    题意:求两串字符(0————255)的最长公共字串 思路:先将两个字符链接起来,中间用一个不曾出现过的字符,然后直接求出height数组,然后根据它的特性,求出最长的公共字串,当然这个最长公共字串的坐 ...

  4. 在sql中根据成绩显示学生排名

    1.准备 create table newtable ( name ), yuwen ), shuxue ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; , ); , ...

  5. Spring整合activiti单元测试

    ** * Spring测试activiti配置是否正常 * <p>Title: SpringActivitiTest</p> * <p>Description: & ...

  6. selenuim爬虫实战 (下)

    SuperLOFTERDownloader7.java package test; import java.io.IOException; import java.util.ArrayList; im ...

  7. springMVC介绍

    http://www.iteye.com/blogs/subjects/springMVC —————————————————————————————————————————————————————— ...

  8. python的post请求抓取数据

    python通过get方式,post方式发送http请求和接收http响应-urllib urllib2 python通过get方式,post方式发送http请求和接收http响应-- import  ...

  9. kettle利用触发器实现数据同步

    2016年8月17日 一.目的 通过触发器实现数据同步二.思路 1.在数据库需要同步的源表中建立一个insert触发器,当有新数据插入时,会自动将新插入数据的主键记录到临时表temp中.(当然也可以记 ...

  10. ubuntu 按键替换 Control_R to Left

    ubuntu 按键替换 Control_R to Left 1 查看当前键盘布局 $xmodmap -pke keycode 105 = Control_R NoSymbol Control_Rkey ...