I am using a local broadcast to let my service know that the AsyncTask has finished its work but I have a small issue : the broadcast is only sent once (it is created by a function that is only called when the app is launched) but I receive it twice.
simplified code :
@Override
protected void onPostExecute(HttpResponse result) {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getBaseContext());
localBroadcastManager.sendBroadcast(new Intent(getString(R.string.bc_CONNECTED)));
}
in the service:
private BroadcastReceiver connectedBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(getString(R.string.app_tag), "broadcast received !!");
}
};
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LocalBroadcastManager.getInstance(this).registerReceiver(connectedBroadcastReceiver, new IntentFilter(getString(R.string.bc_CONNECTED)));
return START_STICKY;
}
Has anyone encountered such a weird behavior yet?