Search code examples
androidalarmmanagerintentservice

IntentService and AlarmManager


Possible Duplicate:
Android RuntimeException: Unable to instantiate the service

I can't find a way to start IntentService from AlarmManager. It is simple for normal service (add it to the manifest, then wrap it up in Intent), but I can't make it work with IntentService - app keeps crashing with "java.lang.RuntimeException: Unable to instantiate service". There is nothing wrong with the IntentService itself (1 line of code). Any help?


Solution

  • There should be no problem to fire IntentService from AlarmManager, and I did it more than once. In the case of IntentService I met cases where a few lines of code were enough to make the problem.

    Make sure your IntentService has a constructor like that:

        public MyIntentService() {
            super("MyIntentService");
        }
    

    Because alarm manager will try to instantiate it with no parameters, and the original IntentService constructor receives String as a parameter.