3

プロジェクトを作成しようとしていますが、異なるパッケージから 1 つのアクティビティと 1 つのサービスがあります。私が1つのプロジェクトに入れた両方のパッケージ。

アクティビティを com.idris.activity に配置し、サービスを com.idris.activity.service に配置しました。

次のように、MyActivity のボタンのリスナーから MyService を呼び出そうとします。

Intent myIntent = new Intent(getApplicationContext(), MyService.class);
                 myIntent.putExtra("extraData", "somedata");
                 startService(myIntent);

アプリケーションのマニフェスト

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="idris.parental.monitor"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MyActivity"
            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=".MyService"
            android:enabled="true" />
    </application>
</manifest>

MyService を起動できません。どうすればよいですか?

4

2 に答える 2

3

マニフェストでこれを使用します。

<service
    android:name=".service.MyService"
    android:enabled="true" />

ファイル内で正しいpackage nameforserviceを使用していることを確認してください。manifestファイルMyService.javacom.idris.activity.service使用よりもパッケージ内にある場合:

<service android:name="com.idris.activity.service.MyService" />
于 2012-07-23T15:46:54.047 に答える
0

ルート pkg 名は package="idris.parental.monitor"であるように見えるため、サービス クラス pkg 名にはこれらをルート パスとして含める必要があり、マニフェストで次のように指定できます。

例えば

サービスパッケージ内のサービス。つまり、idris.parental.monitor.service

マニフェスト内 .service.urservicename

于 2012-07-23T16:40:32.230 に答える