收到广播接收者的意图后未发生变化

时间:2013-04-02 11:34:02

标签: android android-fragments broadcastreceiver

我收到后,我正在adapter.notifyDataSetChanged()listView.invalidateViews() 如果条件说“blabla”成立,则接听电话。但我的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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个

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);

}
}