![](/img/trans.png)
[英]BroadcastReceiver from AlarmManager not receiving in child activities/intent
[英]Changes not reflected after receiving the intent from broadcastreceiver
如果條件為“ blabla”為真,則在收到接收調用后,我正在執行adapter.notifyDataSetChanged()
和listView.invalidateViews()
。 但是我的UI仍然沒有更新。
public class UserFragment extends Fragment{
public class FragmentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(getSetting("CurrentView","").equalsIgnoreCase("blabla")){
adapter.notifyDataSetChanged();
listView.invalidateViews(); //this is not updating the UI.
}
}
注意:我試圖通過再次替換相同的片段來調用相同的UserFragment.java
來更新更改,但這雖然更新了UI但給出了例外IllegalStateException: Can not perform this action after onSaveInstanceState
我剩下的onReceive
方法中的代碼-
UserFragment firstFragment = new UserFragment ();
getSupportFragmentManager().beginTransaction()
.replace(R.id.headlines_fragment, firstFragment)
.addToBackStack(null).commit(); //IllegalStateException: Can not perform this action after onSaveInstanceState
有任何想法嗎?
嘗試這個
public class UserFragment extends Fragment{
public class FragmentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(getSetting("CurrentView","").equalsIgnoreCase("blabla")){
adapter.notifyDataSetChanged();
listView.invalidateViews(); //this is not updating the UI.
UserFragment.this.onCreate(savedInstanceState);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.