Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android method annotation for preventing call from being made on GUI thread

In the project I'm currently working on there are plenty of caching which is done on the main thread which makes the app laggy. My plan is to make asynchronous variants of these, but still keeping the synchronous calls for easier chaining when combined in asyncTasks. The problem I have it that I want to prevent the usage of the caching functions in GUI thread in some intuitive way. Any ideas? Is it possible? Is it possible to mark a method with an annotation which prevents it from being called on the GUI thread?

like image 318
user1354603 Avatar asked Sep 29 '22 07:09

user1354603


1 Answers

http://androidannotations.org/ provides a library that leverages the use of annotations to deal with this. They have annotations such as @UiThread and @Background that essentially replace the need to use runOnUiThread() and AsyncTask respectively.

If you're interested, here's a paper discussing a similar system for dealing with the blocking of UI thread operations from non-UI threads.

like image 144
jpetitto Avatar answered Oct 03 '22 00:10

jpetitto