Skip to content

Instantly share code, notes, and snippets.

@grndvl1
Created April 2, 2019 16:36
Show Gist options
  • Save grndvl1/8ab2fdea6e269726a253761571986665 to your computer and use it in GitHub Desktop.
Save grndvl1/8ab2fdea6e269726a253761571986665 to your computer and use it in GitHub Desktop.
Fix JobIntentService Crash for 8.x Phones
1. Create a new package in your app with name android.support.v4.app This is a workaround to override package-private methods.
2. Create or Edit your Own ServiceClass to Override dequeueWork() method and surround super.dequeueWork() call with try/catch block like the coming snippet.
Any code that uses JobIntent Service override with this class
(Important Note: This fix should be tracked from time to time as any change in the support libraries might break it.)
public abstract class MyServiceImpl extends JobIntentService {
// This method is the main reason for the bug and crash
// the dequeueWork method is called only when the worker service is done
// so no need to call for a restart to the service.
@Override
GenericWorkItem dequeueWork() {
try {
return super.dequeueWork();
} catch (SecurityException exception) {
// the exception will be ignored here.
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment