서비스 의도를 시작할 수 없습니다.
서비스 클래스가 있습니다. 이 클래스를 jar로 내 보냈고 클라이언트 앱에 jar를 포함했습니다.
필요한 경우 서비스 클래스에 전화합니다. 이렇게하면 다음과 같은 오류가 발생합니다.
Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found
동일한 항아리 안에있는 액세스 (해당 클래스의 개체 생성) 할 수있는 서비스 클래스와는 다른 다른 클래스가 있습니다.
내 구성이나 매니페스트 등에서 일부를 놓친 것 같습니다.
같은 것을 식별하도록 도와주세요. 내 코드는 다음과 같습니다.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent () ;
intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ;
this.startService(intent) ; // when I call this line I get the message...
// binding other process continue here
}
클라이언트 manifest.xml
<service android:name="com.sample.service.serviceClass"
android:exported="true" android:label="@string/app_name"
android:process=":remote">
<intent-filter><action android:name="com.sample.service.serviceClass"></action>
</intent-filter>
</service>
미리 감사드립니다,
Vinay
첫째,은 필요하지 않으므로 android:process=":remote"
제거하십시오. 왜냐하면 아무 이익도없이 추가 RAM을 차지하기 때문입니다.
둘째, <service>
요소에 작업 문자열이 포함되어 있으므로 다음을 사용하십시오.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=new Intent("com.sample.service.serviceClass");
this.startService(intent);
}
이 실을 접하는 다른 사람에게는이 문제가 있었고 머리카락을 뽑았습니다. '<application>'종료 태그 DUH!
권리:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
...
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity ...>
...
</activity>
<service android:name=".Service"/>
<receiver android:name=".Receiver">
<intent-filter>
...
</intent-filter>
</receiver>
</application>
<uses-permission android:name="..." />
잘못되었지만 여전히 오류없이 컴파일됩니다.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
...
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity ...>
...
</activity>
</application>
<service android:name=".Service"/>
<receiver android:name=".Receiver">
<intent-filter>
...
</intent-filter>
</receiver>
<uses-permission android:name="..." />
1) 매니페스트의 서비스 선언이 애플리케이션 태그에 중첩되어 있는지 확인
<application>
<service android:name="" />
</application>
2) service.java
활동과 동일한 패키지 또는 diff 패키지에 있는지 확인하십시오.
<application>
<!-- service.java exists in diff package -->
<service android:name="com.package.helper.service" />
</application>
<application>
<!-- service.java exists in same package -->
<service android:name=".service" />
</application>
이 정보로 누군가를 도울 수 있기를 바랍니다. 서비스 클래스를 다른 패키지로 이동하고 참조를 수정했습니다. 프로젝트는 완벽했지만 서비스 클래스는 활동에서 찾을 수 없습니다.
logcat에서 로그인을보고 문제에 대한 경고를 발견했습니다. 활동이 서비스 클래스를 찾을 수 없었지만 재미있는 점은 패키지가 잘못되었고 "/"문자가 포함되어 있다는 것입니다. 컴파일러가 찾고 있던
com.something./service.MyService
instead of
com.something.service.MyService
I moved the service class out from the package and back in and everything worked just fine.
In my case the 1 MB maximum cap for data transport by Intent. I'll just use Cache or Storage.
I've found the same problem. I lost almost a day trying to start a service from OnClickListener
method - outside the onCreate
and after 1 day, I still failed!!!! Very frustrating! I was looking at the sample example RemoteServiceController
. Theirs works, but my implementation does not work!
The only way that was working for me, was from inside onCreate
method. None of the other variants worked and believe me I've tried them all.
Conclusion:
- If you put your service class in different package than the mainActivity, I'll get all kind of errors
Also the one "/" couldn't find path to the service, tried starting with
Intent(package,className)
and nothing , also other type of Intent startingI moved the service class in the same package of the activity Final form that works
Hopefully this helps someone by defining the listerners
onClick
inside theonCreate
method like this:public void onCreate() { //some code...... Button btnStartSrv = (Button)findViewById(R.id.btnStartService); Button btnStopSrv = (Button)findViewById(R.id.btnStopService); btnStartSrv.setOnClickListener(new OnClickListener() { public void onClick(View v) { startService(new Intent("RM_SRV_AIDL")); } }); btnStopSrv.setOnClickListener(new OnClickListener() { public void onClick(View v) { stopService(new Intent("RM_SRV_AIDL")); } }); } // end onCreate
Also very important for the Manifest file, be sure that service is child of application:
<application ... >
<activity ... >
...
</activity>
<service
android:name="com.mainActivity.MyRemoteGPSService"
android:label="GPSService"
android:process=":remote">
<intent-filter>
<action android:name="RM_SRV_AIDL" />
</intent-filter>
</service>
</application>
참고URL : https://stackoverflow.com/questions/3439356/unable-to-start-service-intent
'your programing' 카테고리의 다른 글
대 코드에서 한 번 클릭으로 미리보기 파일을 비활성화하는 방법은 무엇입니까? (0) | 2020.10.07 |
---|---|
곡선 경로를 따라보기 또는 이미지의 움직임을 애니메이션하려면 어떻게해야합니까? (0) | 2020.10.07 |
Java : 명령 줄 인수가 null인지 확인 (0) | 2020.10.07 |
ARC를 사용한 @property 정의 : 강하거나 유지합니까? (0) | 2020.10.07 |
모듈을 여러 파일로 분할 (0) | 2020.10.07 |