Reputation: 168
If I start my Service
from Activity
it runs properly (by clicking button). However it does not work if I start it from BrodcastReceiver
. What am I doing wrong?
Here is my code of Service
, BroadcastReceiver
Here is my manifest file http://pastebin.com/fUcM6Qse
Upvotes: 2
Views: 2547
Reputation: 2899
Here is how I do it, and it works:
public class BadgesReceiver extends BroadcastReceiver {
private static final String TAG = "BadgesReceiver";
public static final String BADGES_UPDATE_ACTION = BuildConfig.PACKAGE_NAME + ".action.UPDATE_BADGES";
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent != null ? intent.getAction() : null;
Log.d(TAG, "onReceive action: " + action);
if (!TextUtils.isEmpty(action) && action.equals(BADGES_UPDATE_ACTION)) {
final Intent i = new Intent(context, MyService.class);
i.setAction(MyService.UPDATE_BADGES_ACTION);
context.startService(i);
}
}
}
Upvotes: 1