내부 BroadcastReciver에 의해 조치를받을 방법 :는 PendingIntent로 위젯 발송에 실패 의도 수신와 내가 문제가있는 서비스
intent = new Intent(MyService.MY_ACTION);
pendingIntent = PendingIntent.getService(this, 0, intent, 0);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
을 나는이면 MyService에 방송 수신기를 추가 :
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d(TAG, "Intent command received");
String action = intent.getAction();
if(MY_ACTION.equals(action))
{
doSomeAction();
}
}
};
을 마지막으로 나는 등록 이 수신기 나는 서비스의 방법을 창조한다 :
IntentFilter filter = new IntentFilter();
filter.addAction(MY_ACTION);
registerReceiver(mIntentReceiver, filter);
그리고 지금 thth MyServi CE가 실행되고 내가 버튼을 클릭 내가 얻을 :
09-21 14:21:18.723: WARN/ActivityManager(59): Unable to start service Intent { act=com.myapp.MyService.MY_ACTION flg=0x10000000 bnds=[31,280][71,317] }: not found
나는 또한이면 MyService에 파일을 명시하기 위해 (MY_ACTION의 조치) 인 텐트 필터를 추가하려고하지만이면 MyService의 방법을 onStartCommand 호출됩니다. 그리고 그것은 내가 원하는 것이 아닙니다. mIntentReceiver의 onReceive 메서드를 호출해야합니다.
친절하게 도와 주시고이 문제를 도와주십시오. 감사 !
감사합니다. 그것은 좋은 지적입니다! 이제 알았어요. – Bhiefer
@aromero, 고마워요! 나는 약 2 시간 동안 SO를 찾고 있었고 나의 문제에 대한 이유를 찾으려고 노력했다. 그러나 당신의 대답은 마침내 나를 올바른 곳으로 인도했습니다! – AntonSack