首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@后台正在EFragment的UI主线程中执行

@后台正在EFragment的UI主线程中执行
EN

Stack Overflow用户
提问于 2014-04-08 00:15:35
回答 1查看 384关注 0票数 0

在Android-注释中,@后台并不是在创建单独的线程。相反,这段代码正在主UI线程中运行。我根据以下守则得出这个结论:

代码语言:javascript
复制
@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()));
}

结果是:-

代码语言:javascript
复制
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

有没有办法解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-08 06:14:05

这里有两件事:

  1. 你能告诉我们你是如何发起这个测试活动的吗?我怀疑您使用的是原始活动,而不是生成的活动。
  2. 正如@selvin所说,您应该使用Thread.currentThread()来获取当前线程。要检查它是否是主线程,请使用以下代码片段:Thread.currentThread() == Looper.getMainLooper().getThread()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22925366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档