我一直在使用android上的线程概念挣扎。我认为下面的代码是在不同的线程上运行到主UI线程,但我不是100%确定的,所以我认为我会来澄清,因为Android文档没有用我理解的任何语言编写。下面是我的代码。此代码是否在与主UI线程不同的线程中执行
public void retrieveImages(final ImagePresenterInt imagepresenter) {
storedImages = new ArrayList<Image>();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
File imagedir = new File("/mnt/shared/images");
File [] myfiles = File.listRoots();
String canread = String.valueOf(imagedir.canRead());
String isfile = String.valueOf(imagedir.isFile());
String isdir = String.valueOf(imagedir.isDirectory());
Log.d("Can Read?","Canread from file :" + canread);
Log.d("is file?","Is a file ? :" + isfile);
Log.d("is dir?","Is a Dir file :" + isdir);
File [] rootfiles =myfiles[0].listFiles();
for (File item : rootfiles)
{
Log.d(item.getAbsolutePath(),item.getName());
}
if(Looper.myLooper() == Looper.getMainLooper())
{
Log.d("main thread ?", "YES");
}
}
}, 2000);
}
我对上述代码的理解是我创建了一个处理程序。它与主线程或UI线程相关联。它有一个消息队列和一个与之关联的活套。这段代码被传递给消息队列并由循环线程运行到主UI线程?我可能在这里错了。但主要是我想知道这是否在主线程上运行。如果不是,我将如何把它放到不同的线程上?我试图验证码是在不同的线程使用运行的代码我在这个问题
How to check if current thread is not main thread
这显然告诉我荫仍然在主线程中运行的发现。感谢您的帮助
尝试更新和查看或ui项目在你使用的线程,如果错误,那么它不是主线程或UI线程 – Meenal 2014-09-11 13:29:44
你的意思是尝试更新视图或UI项目? – 2014-09-11 13:40:45
ui item..like imageview或textview – Meenal 2014-09-11 13:41:20