Question

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?

Était-ce utile?

La solution

Two things here :

  1. Could you tell us how you're launching this test activity ? I suspect that you're using the original activity instead of the generated one.
  2. As @selvin said, you should use Thread.currentThread() to get the current thread. And to check if it's the main thread, use this snippet : Thread.currentThread() == Looper.getMainLooper().getThread().
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top