마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

다른 project의 service를 실행하고 싶습니다.

0 추천
안녕하세요, 안드로이드 초보 입문자 입니다. service 관련 질문이 있습니다.

A라는 project(package)가 있고 A는 아래와 같이 service를 가지고 있습니다.

public class MainNoteService extends Service implements Runnable{

....

}

그리고 A의 manifest.xml에 아래와 같이 service를 등록했습니다.

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       
        <service android:name="com.example.notecompressionservice.MainNoteService"
            android:enabled="true"
            android:exported="true">
                <intent-filter>
                       <action android:name="com.example.notecompressionservice.CompressNote"/>
                       <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
         </service>
    </application>

 

그리고 B라는 project가 있습니다. B project의 properties에서 A project를 library로 참조하도록 설정 했습니다.

그리고 B project의 active에서 아래와 같이  A가 가진 service를 call하고 있습니다.

Intent intent = new Intent("com.example.notecompressionservice.CompressNote");
        startService(intent);

위와 같이 호출하면 "Unable to start service Intent { act=com.example.notecompressionservice.CompressNote }: not found" error??waring?? 이 발생하는데요.

위와 같은 상황에서 A의 service를 어떻게 해야 B에서 호출 할 수 있을까요?

조언 부탁드립니다.

감사합니다.
익명사용자 님이 2013년 3월 4일 질문

1개의 답변

0 추천

Intent생성이 잘못되었습니다. 레퍼런스 문서를 보시면 new Intent(String) 에서 주는 String은 action값을 지정해주는것을 확인하실수 있을겁니다. 근데 지금 원하신는 것은 액션을 지정하는 것이 아니라 컴포넌트를 지정하는 것이기 때문에

Intent intet = new Intent();
intent.setClassName("com.example.notecompressionservice", "com.example.notecompressionservice.CompressNote");

와 같이 앞에는 패키지 문자열, 뒤에는 클래스 문자열을 넣어서 만드시면 됩니다.

회색 (21,340 포인트) 님이 2013년 3월 4일 답변
...