开发者

Android annotation to run on Ui Thread

Is it possibl开发者_Go百科e to annotate method to run code in UiThread?

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

looks too complex to use it often.


Look at the AndroidAnnotations project. They use a annotations. As far as i know it is what you want. It uses compile time code generation http://code.google.com/p/androidannotations/


Note:

According to the documentation the @UiThread annotation only denotes that the given class/method should run on the UI thread. It does NOT mean using this annotation will call your method on the UI thread.


Edit: this answer is not relevant any more. You can annotate with @UiThread.

According to Google IO 2015, @UiThread is the annotation you are looking for. There will be actually four new: http://robovm.com/google-io-summary-whats-new-in-android-development-tools/ (under New Support Annotations).

Sadly, they are not live yet. When they will be live, they will pop up in here: https://developer.android.com/reference/android/support/annotation/package-summary.html


@UiThreadTest seems to work now. I'm sure it will be deprecated for the real thing soon, so caveat emptor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜