Skip to content Skip to sidebar Skip to footer

Cannot Start Service In Inner Class - Is It My Android Manifest?

Please help! I am desperate here!!!! I am having trouble starting my service. I moved it to an inner class within my Activity and I cannot get it to start! I don't know if I have t

Solution 1:

Your Service must be a static class. Then once in your manifest, you will need to show it as so

<service android:name="HW07$PrimeService"/>

You could do something like this (pseudo)

class HM07 extends Activity {

    public static Handler mHandler;
    // ...

    @Override public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // ...

        mHandler = new Handler();
    }
}

class PrimeService extends Service {
    @Override public void onStartCommand() {
        Handler handler = HM07.mHandler;
        handler.sendMessage(/* Message */);
    }
}

Solution 2:

class outclass extends Activity {
   // ...
   @Override
   public void onCreate(Bundle icicle) {
       super.onCreate(icicle);
       // ...
   }

   public static class innerService extends Service {
       @Override
       public void onStartCommand() {
           //....
       }
   }
}

and you need to declare below to your Androidmanifest.xml

<service android:name=".outclass$innerService"/>

note the dollar sign !


Post a Comment for "Cannot Start Service In Inner Class - Is It My Android Manifest?"