[英]Greenrobot Eventbus holds variables
我有以下症狀的Eventbus出現了問題。 我的活動開始了另一項活動。 使用了Eventbus和布爾值集。 在活動運行期間更改此值。 第一次運行就可以,但是在第二次運行中,我在前一次運行中更改了錯誤的值。 這是代碼:
公共類ListArchiveTabs擴展FragmentActivity {
private boolean isStartFragment = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isStartFragment = true;
EventBus.getDefault().registerSticky(this);
System.out.println("Create archive activity " + isStartFragment);
}
@Override
public void onDestroy()
{
super.onDestroy();
EventBus.getDefault().unregister(this);
System.out.println("Destroy archive activity");
}
public void onEventMainThread(GetArchiveEvent event)
{
if(isStartFragment == true) {
isStartFragment = false;
} else {
}
}
}
在第一次運行中,isStartFragment為true,但其他運行顯示為false。
onEventMainThread
在主線程中運行的方法,第一次運行時,沒有任何事件,再次發生時,要在同一線程中執行,則依次執行,為什么將標志更改為false,將事件更改為在線程上執行或更改標志的邏輯,請記住sticky
是一個正在進行的事件並以這種方式注冊,查看是否存在此類事件,然后直接調用其onEvent
從而按順序執行該標志改變了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.