Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 971
Andrei Buneyeu Avatar asked Mar 07 '11 09:03

Andrei Buneyeu


2 Answers

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.

like image 63
ludwigm Avatar answered Oct 26 '22 17:10

ludwigm


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

like image 33
Ariel Cabib Avatar answered Oct 26 '22 17:10

Ariel Cabib