Android注解在UI线程上运行

11

有没有可能用注释的方式在UiThread中运行代码?

runOnUiThread(new Runnable() {
public void run() {
//my code
}});

看起来太复杂了,不太适合经常使用。


你在论坛上发布了关于PanoramaSample项目的问题吗?我检查了git论坛的问题列表,但没有找到相关内容。 - Rohit Patil
3个回答

19

看一下 AndroidAnnotations 项目。它们使用注解。据我所知,这正是你想要的。它使用编译时代码生成。http://code.google.com/p/androidannotations/


注意:

根据文档@UiThread 注解仅表示给定的类/方法应该在 UI 线程上运行。这并不意味着使用此注解将在 UI 线程上调用您的方法。


注意正确导入,AndroidAnnotations 和 support 注释都被称为 @UiThread。 - Display name

4

根据文档所述,“Denotes that the annotated method or constructor should only be called on the UI thread.”,因此仅用于文档目的。 - Auras

0

@UiThreadTest 现在似乎可以工作了。我相信它很快就会被真正的东西所取代,所以请谨慎使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接