我有一个BroadcastReceiver
清单
<receiver android:name=".NetworkStateChecker">
<intent-filter >
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"
/>
</intent-filter>
</receiver>
这是课程
public class NetworkStateChecker extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null) {
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI || activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
new AutoTask().execute("start");
}
}
}
}
当异步任务完成后,我称之为
context.sendBroadcast(new Intent(act1.DATA_SAVED_BROADCAST));
context.sendBroadcast(new Intent(act2.DATA_SAVED_BROADCAST));
context.sendBroadcast(new Intent(act3.DATA_SAVED_BROADCAST));
这是我其中一项活动的样本
public class act1extends AppCompatActivity {
public static final String DATA_SAVED_BROADCAST = "website link";
private BroadcastReceiver broadcastReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
registerReceiver(new NetworkStateChecker(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
//Codes here
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Codes here
}
};
registerReceiver(broadcastReceiver, new IntentFilter(DATA_SAVED_BROADCAST));
}
}
这是场景。广播接收器工作后,我将去做一些活动,然后回到上面的活动。接下来是当我去参加另一项活动并在按下广播后无法再执行一些操作
出什么问题了?我该如何解决?