Broadcastreceiver Fires Multiple Times (providers_changed_action)
Why BroadcastReceiver was trigger multiple time. My Sample Project is like below code ANDROID MANIFEST
Solution 1:
Use below concept for handling multiple broadcast event:
private BroadcastReceiver gpsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
String action = intent.getAction();
if (!TextUtils.isEmpty(action) && action.equals(LocationManager.PROVIDERS_CHANGED_ACTION)) {
//Do your stuff on GPS status change
showDialogHandler.removeMessages(1);
showDialogHandler.sendEmptyMessageDelayed(1, 2000);
}
}
}
};
private Handler showDialogHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message message) {
if (message.what == 1) {
showDialogHandler.removeMessages(1);
// do your action
}
return true;
}
});
Post a Comment for "Broadcastreceiver Fires Multiple Times (providers_changed_action)"