Hide a ProgressDialog once data is loaded
You are able to do it but you need to use not static but dynamic BroadcastReceiver. So here is solution:
At first, register in your Activity BroadcastReceiver dynamically:
private void registerReceiver() {
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Const.LOADING_COMPLETE_ACTION)) {
if (dlg != null) {
dlg.dismiss();
}
}
}
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Const.LOADING_COMPLETE_ACTION);
registerReceiver(receiver, intentFilter);
}
And then in your IntentService, all what you need is to send Broadcast:
sendBroadcast(new Intent(Const.LOADING_COMPLETE_ACTION));
Note: Also define your ProgressDialog variable on Activity scope to have access to it from onReceive() method.