Andrei Buneyeu
Andrei Buneyeu

Reputation: 6680

Android annotation to run on Ui Thread

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

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

looks too complex to use it often.

Upvotes: 11

Views: 12074

Answers (3)

ludwigm
ludwigm

Reputation: 3383

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.

Upvotes: 19

Ariel Cabib
Ariel Cabib

Reputation: 2102

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

Upvotes: 4

Peter McLennan
Peter McLennan

Reputation: 503

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

Upvotes: 0

Related Questions