在Android-注释中,@后台并不是在创建单独的线程。相反,这段代码正在主UI线程中运行。我根据以下守则得出这个结论:
@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()));
}结果是:-
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有没有办法解决这个问题?
发布于 2014-04-08 06:14:05
这里有两件事:
Thread.currentThread()来获取当前线程。要检查它是否是主线程,请使用以下代码片段:Thread.currentThread() == Looper.getMainLooper().getThread()。https://stackoverflow.com/questions/22925366
复制相似问题