(POST 코드) ...는 서비스가 시작되지 수 - 내가하기로되어있는 체크 박스를 가지고 내가, 멍청한 놈 질문에 대한 유감 자바 멍청한 놈이야
을 시작하고 체크 박스로 사망 점검 할 때 서비스를 끄십시오 - 선택하지 않으면 서비스를 종료하십시오. "시도 중 ..."토스트가 예상대로 튀어 나오지만 서비스가 시작되지 않은 것으로 보이고 토스트가 표시되지 않습니다.
여기 내 주요 항목, 기본 활동 코드 (요약) 및 서비스 코드 :
// manifest entries
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<activity android:name=".MainMenu" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".PPS" android:process=":remote" android:label="@string/service_name" />
</application>
// MainMenu.java
final CheckBox checkBoxStartService = (CheckBox) findViewById(R.id.checkBoxEnable);
checkBoxStartService.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (checkBoxStartService.isChecked() == true)
{ // make toast
Toast toaster = Toast.makeText(MainMenu.this, "attempting to start service...", 500);
toaster.setGravity(Gravity.CENTER, 0, -200);
toaster.show();
Intent startPPS = new Intent();
startPPS.putExtra("com.domain.notlaunchingservice.PPS", false);
startService(startPPS);
}
if (checkBoxStartService.isChecked() == false)
{
Intent closePPS = new Intent();
closePPS.putExtra("com.domain.notlaunchingservice.PPS", true);
stopService(closePPS);
}
}
};
// PPS.java
package com.domain.notlaunchingservice;
import android.app.Service;
import android.view.Gravity;
import android.widget.Toast;
public abstract class PPS extends Service
{
@Override
public void onCreate()
{
Toast toasty = Toast.makeText(PPS.this, "service created!", 500);
toasty.setGravity(Gravity.CENTER, 0, 200);
toasty.show();
};
public void onDestroy()
{
Toast toasted = Toast.makeText(PPS.this, "service destroyed!", 500);
toasted.setGravity(Gravity.CENTER, 0, -200);
toasted.show();
};
};
는 나는 또한 사용하여 서비스를 호출하는 것을 시도했다 :
startService(new Intent(MainMenu.this, PPS.class));
이 앱이 예기치 않게 종료하고 난 힘 닫기를 클릭 말하는 에뮬레이터에서 오류를 반환하지만 주요 활동은 '아무튼 t 닫기, 그래서 나는 그것이 servi라고 가정하고있다. 그게 내가 강제로 닫는 거지. 내가 서비스를 시작하는 방법을 주요 활동 포커스를 잃을 또는 후에 그것은 SQL 기반을로드하고 파일에 기록 오디오를 계속할 수
java.lang.RuntimeException: Unable to instantiate service com.domain.notlaunchingservice.PPS
내가 한 상관 없어 : 아래 DDMS의 출력 닫은.
완료되면 시장에서 무료로 제공되는 앱이므로 프로젝트가 황금 시간대에 준비되면 많은 도움을받을 수 있습니다.
컴파일되지만 서비스가 시작되지 않습니다. – notgoodwithjava
두 번째 방법을 사용하면 서비스가 시작된 것처럼 보입니다. – notgoodwithjava
링크를 이용해 주셔서 감사합니다. 지금 읽어 보겠습니다. – notgoodwithjava