4

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?

Matthew Hoggan
  • 7,402
  • 16
  • 75
  • 140

1 Answers1

6

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)

dymmeh
  • 22,247
  • 5
  • 53
  • 60
  • I updated my answer to fix how you're referencing your inner class which is likely why it wasn't called. And yes, you aren't going to be able to access your outer class when the class is static. You'll need to pull that functionality into the intent service – dymmeh Oct 01 '13 at 21:56
  • 1
    Then, **it's not possible**. You cannot have a Service instance whose class is not static. – Cristian Oct 01 '13 at 21:56
  • Okay it is now being called. I just have to figure out how to get alot of code into the onHandleIntent() method. That is my problem thought +1. For those interested the outer class is a singleton. Made things a bit easier. – Matthew Hoggan Oct 01 '13 at 21:58