android – 检查是否在使用robolectric的UI-Thread上调用了一个方法

android – 检查是否在使用robolectric的UI-Thread上调用了一个方法,第1张

概述这里的任何人都知道如何编写测试(或理想情况下有一个示例)来检查是否在UI-Thread上调用了一个方法? 答案来自以下链接: How to check if current thread is not main thread How to know if this thread is a UI Thread 1)Looper.myLooper()== Looper.getMainLooper() 这里的任何人都知道如何编写测试(或理想情况下有一个示例)来检查是否在UI-Thread上调用了一个方法?解决方法 答案来自以下链接:

How to check if current thread is not main thread

How to know if this thread is a UI Thread

1)Looper.myLooper()== Looper.getMainLooper()

2)AndroID应用程序只有一个UI线程,因此您可以在Activity回调中的某个位置(如onCreate())检查并存储其ID,然后将该线程的ID与存储的ID进行比较.

mMainThreadID = Thread.currentThread().getID();

3)如果你想在UI线程上做一些事情,并通过使用任何对Activity的引用

mActivity.runOnUiThread( new Runnable() {    @OverrIDe     public voID run() {    ...    }});

希望能帮助到你

总结

以上是内存溢出为你收集整理的android – 检查是否在使用robolectric的UI-Thread上调用了一个方法全部内容,希望文章能够帮你解决android – 检查是否在使用robolectric的UI-Thread上调用了一个方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1129940.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存