In Android-Annotations, @Background is not creating a separate thread. Instead this code is being run in main UI Thread. I come to this conclusion, on the basis of following code :-
@Background
void doGetMoreDishesWishedList() {
Log.d(TAG, "doGetMoreDishesWishedList");
Log.d(TAG, Integer.toString(android.os.Process.myTid()));
if (Looper.myLooper() == Looper.getMainLooper())
Log.d(TAG, "In main loop");
else
Log.d(TAG, "Not In main loop");
}
@UiThread
void updateUiGetMoreDishesWishedList(long requestSentTime, ArrayList<UserDishContainer> newList) {
Log.d(TAG, "updateUiGetMoreDishesWishedList");
Log.d(TAG, Integer.toString(android.os.Process.myTid()));
}
Result is :-
04-07 21:11:33.359: D/WishlistFragment(26346): doGetMoreDishesWishedList
04-07 21:11:33.359: D/WishlistFragment(26346): 26346
04-07 21:11:33.359: D/WishlistFragment(26346): In main loop
04-07 21:11:34.372: D/WishlistFragment(26346): updateUiGetMoreDishesWishedList
04-07 21:11:34.372: D/WishlistFragment(26346): 26346
Is there any way to solve this issue?
Two things here :
Thread.currentThread()
to get the current thread. And to check if it's the main thread, use this snippet : Thread.currentThread() == Looper.getMainLooper().getThread()
.