问题
My nested intent services is defined as follows:
package com.my.package;
... // Bunch of imports
public class MyNotifier
... // Bunch of variables
public class MissedCallIntentService extends IntentService {
private static final String TAG = "MissedCallIntentService";
public MissedCallIntentService() {
super("MissedCallIntentService");
Log.i(TAG, "Creating intent service.");
}
@Override
public void onHandleIntent(Intent intent) {
Log.i(TAG, "Handling intent service.");
}
}
// Test my nested intent filter
public MyNotifier(Context app) {
mApp = app;
Log.i(LOG_TAG, "Going to start intent service.");
Intent intent = new Intent(mApp, MissedCallIntentService.class);
mApp.startService(intent);
}
... // Bunch of functions
}
My AndroidManifest.xml file has the following in it:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
// Protected Broadcasts
// Permissions
<application ...>
<service android:name="com.my.package.MyNotifier.MissedCallIntentService" >
</service>
<activity android:name="ActivityOne"
android:label="@string/activity_one"
<intent-filter>
...
</intent-filter>
</activity>
<activity android:name="ActivityTwo"
android:label="@string/activity_two"
<intent-filter>
...
</intent-filter>
</activity>
<activity android:name="ActivityThree"
android:label="@string/activity_three"
<intent-filter>
...
</intent-filter>
</activity>
</application>
</manifest>
After building my app then pushing it to the phone and running it this is all I see.
$ make_magic && adb remount && adb push MyApp.apk /system/app/ && adb reboot && adb logcat | grep 'intent\ service'
make: Leaving directory `BuildDir'
remount succeeded
6149 KB/s (6036528 bytes in 0.958s)
- waiting for device -
I/MyNotifier( 1184): Going to start intent service.
I should see:
I/MyNotifier( XXXX): Going to start intent service.
I/MissedCallIntentService( XXXX): Creating intent service.
I/MissedCallIntentService( XXXX): Handling intent service.
Thus the point of my question. What do I need to add to get my intent service called?
回答1:
Declare the nested inner class as static or define it in it's own class (and update the manifest if you do)
And if you reference an inner class the reference should be
<service android:name="com.my.package.MyNotifier$MissedCallIntentService" />
(note the dollar sign)
来源:https://stackoverflow.com/questions/19126215/android-nested-intent-service-not-being-started-after-call-to-context-startserv