广播接收器在onResume后不工作

时间:2018-12-02 09:16:40

标签: android android-fragments android-activity broadcastreceiver

我已经在broadcast receiver的onResume中注册了fragment,但是根本没有触发,虽然调用了onResume()方法,但是在注册后broadcast receiver无法正常工作onResume()。与activity的情况相同,我在某些activity中使用了此代码,但从未调用过broadcast receiver。第一次触发是因为我也在onCreate中注册了广播接收器,但是即使我在onResume中再次注册了它,也不会调用onResume

@Override
    public void onPause() {
        super.onPause();
        LocalBroadcastManager.getInstance(this).unregisterReceiver(tagAddedToSearch);
        LocalBroadcastManager.getInstance(this).unregisterReceiver(tagRemovedFromSearch);

    }


 @Override
    public void onResume() {
        super.onResume();

        Log.e(" on resume","onresume tag serach");
        LocalBroadcastManager.getInstance(this).registerReceiver(tagRemovedFromSearch,
                new IntentFilter("removeFeedTag"));
        LocalBroadcastManager.getInstance(this).registerReceiver(tagAddedToSearch,
                new IntentFilter("addFeedTag"));
        ////check app update of app
//        CheckAppUpdate.with(getContext()).onUpdateNeeded(getContext()).check();
    }

1 个答案:

答案 0 :(得分:0)

使用以下方法创建广播接收器后,应发送广播:

sendBroadcast

如果不发送,则无法触发广播。