如果我从Service
启动Activity
,它就会正常运行(点击按钮)。但是,如果我从BrodcastReceiver
启动它,它就不起作用。我究竟做错了什么?
这是我的Service
,BroadcastReceiver
这是我的清单文件 http://pastebin.com/fUcM6Qse
答案 0 :(得分:1)
我是这样做的,它有效:
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);
}
}
}