아래의 서비스는 다른 앱에서 버튼 클릭을 통해 트리거됩니다 (보류중인 Intent 실행). onStartCommand()는 Messages를 만들고 send() 메서드를 사용하여 전달합니다. 이상적으로는, onClickCommand를 호출 할 때마다 버튼이 클릭되는 것을 기대합니다. 보류중인 인 텐트는 buttonClick에서 서비스를 시작하는 데 사용됩니다.onStartCommand() 서비스가 여러 번 시작된 경우에도 한 번만 호출
하지만 onstartCommand()는 처음으로 버튼을 한 번만 호출됩니다. 후속 버튼을 클릭해도 onStartCommand()가 트리거되지 않습니다.
흥미롭게도 제가 행을 주석으로 달려면 replyTo.send (msg); onStartCommand는 다른 앱에서 버튼을 클릭 할 때마다 호출됩니다.
따라서 서비스 내에서 android IPC Messenger를 사용하여 메시지를 발송하는 것이 문제의 원인 일 수 있습니다. 메시지가 목적지 앱에 성공적으로 도달했음을 확인했습니다. 발신 통화 차단과 같은 메시지에 대한 세부 정보가 누락 되었습니까?
onStartCommand()에서 'START_STICKY'을 (를) 반환하고 있는데 그 이유가 될 수도 있습니다.
어떤 일이 일어나고 있는지에 대한 통찰력을 환영합니다.
//MyService.java
@Override
public void onCreate() {
// create RemoteViews -> rView
Intent intent = new Intent(getBaseContext(), MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(getBaseContext(), 0, intent, 0);
rView.setOnClickPendingIntent(buttonId, pendingIntent);
//On click of the above button, this MyService will be started usingthe given pendingintent
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("debug","Service onStartCommand");
Message msg = Message.obtain(null, UPDATE_REMOTE_VIEW, rView);
try {
replyTo.send(msg);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return START_STICKY;
}
보너스 세부 사항 : (다른 응용 프로그램에서) 버튼에 pendingIntent는 setOnclickPendingIntent() (리모트 뷰 RemoteViews 클래스)를 사용하여 설정됩니다. 문서에서
그 '메시지 메시지'로 무엇을하고 있습니까? – pskink
@pskink MyService에서 MyApp로 보내는 msg은 MyService에서 수행 된 계산을 기반으로 일부보기를 업데이트하도록 MyApp에 지시합니다. –
왜냐하면'replyTo.send (msg); 행에 주석을 달면 "특별하지 않습니다"; onStartCommand는 다른 앱에서 버튼을 클릭 할 때마다 호출됩니다. ' – pskink