서비스가 활성화 될 때 왜 내게 messageboxdialog를 보여주지 않습니다.안드로이드 서비스 클래스
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
player.start();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
AlarmService.this.onDestroy();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
}
사운드가 재생되고있는 토스트가 나타나고 있습니다. 왜 쇼 다이얼로그는 오지 않았습니까?
서비스에서 대화 상자를 만들 수 없습니다. 이 게시물을 참조하십시오 : http://stackoverflow.com/questions/5126868/showing-an-ok-dialog-box-from-a-service-receiver-in-android – AedonEtLIRA
내가 원하는 것은 제게 버튼을 보여줄 때입니다. 서비스가 멈추기 위해 실행 중입니다. 그렇다면 서비스에서 Intent를 작성하고 onDestroy() 메소드가 서비스를 중지시키는 다른 Activity를 호출해야한다고 생각합니까? – Samuel
활동이 전혀 필요하지 않습니다. 이 서비스에는 ** stopService (Intent) ** 메소드가 있습니다. 그냥 부르세요. http://developer.android.com/reference/android/content/Context.html#stopService%28android.content.Intent%29 – AedonEtLIRA