Android error: java.lang.illegalstateexception: not allowed to start service intent
Error resolution 12
Today’s test threw me a crash message:
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=xxx }: app is in background uid UidRecord{xxx u0a136 CEM idle procs:1 seq(0,0,0)}
Can it be hard for me
once you see it, you can see that it’s a background service startup error. Just put the service in the foreground, easy
In fact, Google took a look
https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten
The problem is that Android 8.0 does not allow the creation of background services.
Solution:
Method 1:
The simplest way is to directly open the front desk service
set the service to the front desk in oncreate of your service class
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForeground(1, new Notification());
}
Of course, this method will show what is running on the status bar of Android 5.0 and 6.0 phones please refer to the following method
Method 2:
The method from here
first modify the service configuration in your manifest file
<service android:name=".YourService"
android:permission="android.permission.BIND_JOB_SERVICE"/>
Then change the modification inheritance of your service class to extensions jobintentservice
and add the following code
public static final int JOB_ID = 1;
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, YourService.class, JOB_ID, work);
}
@Override
protected void onHandleWork(@NonNull Intent intent) {
// your code
}
The startup service is modified as follows.
YourService.enqueueWork(context, new Intent());
However, I tested that the content in onstartcommand() does not execute. No reason has been found
I hope you can help me with the analysis.
It’s over
Read More:
- How to Solve Error: Android java.lang.IllegalStateException: Could not execute method of the activity
- [Solved] Android mediaplayer.prepare() Error: Caused by: java.lang.IllegalStateException
- Android studio can’t start, running error: warning: crash service did not start
- [Solved] java.lang.IllegalStateException: Cannot get a STRING value from a NUMERIC cell
- JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token
- [Solved] Android DataBinding Error: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 fragment Changes to Fragm
- Flash back problem when Android studio plays music in sdcard through intent
- Android studio configurate intent-filter and compile error [Solved]
- [Solved] swagger3 Error: org.springframework.context.ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException
- [Solved] HTTP Error 405.0-Method Not Allowed occurs in the Put operation of the REST service on IIS7.5
- [Solved] ViewBinding Error: java.lang.ClassCastException: android.widget.RelativeLayout cannot be
- [Solved] Playbook Start Nginx Error: Unable to start service nginx: Job for nginx.service fd with error code
- How to Fix Error 1069:The service did not start due to a logon failure
- Start error in maven web project java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener
- [Solved] Android MediaRecorder.stop() Error: java.lang.RuntimeException: stop failed.
- [Android Error] java.lang.RuntimeException: An error occurred while executing doInBackground()
- [Solved] Android Studio Start Error: Missing essential plugin: org.jetbrains.android Please reinstall Android
- [Solved] Windows Android Studio Cannot Start Error: Internal error. Please refer to https://code.google.com/p/android/issue
- Java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; error resolution