You cannot have non-static inner Service class. If you want to have an inner Service class, declare it as static and specify it in manifest file:
<service android:name="com.my.package.OuterClass$InnerServiceClass" />
Question
I have this IntentService
inside a class. The intent service is not starting. What am i doing wrong?
public class getListOfUsersService extends IntentService {
public getListOfUsersService() {
super("DownloadListOfUsersIntentService");
System.out.println("intentService started");
}
@Override
protected void onHandleIntent(Intent intent) {
System.out.println("intentService onHandle started");
mService.sendMessage(Protocols.REQUEST_SEND_USER_LIST);
while(true) {
UserHolder UH = new UserHolder();
String usersdata = mService.getString();
System.out.println("userdata: "+ usersdata);
String array[] = usersdata.split("<!!>");
UH.setUserName(array[1]);
UH.setUserPhoneNum(array[2]);
userHolderList.add(UH);
System.out.println("added to usersList");
if(isDone) break;
}
}
}
I start it in a method :
public void update() {
System.out.println("update");
Intent intent = new Intent(this, getListOfUsersService.class);
startService(intent);
}
I registered it in the Manifest:
<service
android:name=".getListOfUsersService"
android:exported="false"/>
Solution
You cannot have non-static inner Service class. If you want to have an inner Service class, declare it as static and specify it in manifest file:
<service android:name="com.my.package.OuterClass$InnerServiceClass" />
OTHER TIPS
Is <service ...>
a child of <application...>
? If it's not, it may be the problem.
One more suggestion is to use the context returned by getApplicationContext(), but that should not be thus important.