Android Annotations for Ui Thread

Is it possible to annotate a method to run code in UiThread?

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

It looks too complicated to use it often.

+7
source share
3 answers

Take a look at the AndroidAnnotations project. They use annotations. As far as I know, this is what you want. It uses compilation time generation http://code.google.com/p/androidannotations/


Note:

According to the documentation, the @UiThread annotation @UiThread means that the given class / method should work on the user interface thread. It does NOT mean that using this annotation will call your method in the user interface thread.

+14
source

Edit: This answer is no longer relevant. You can annotate with @UiThread .

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

Unfortunately, they do not yet live. When they live, they will appear here: https://developer.android.com/reference/android/support/annotation/package-summary.html

+4
source

@UiThreadTest now works. I am sure this will be obsolete for the real thing soon, so caution emptor.

0
source

All Articles