host.activity is my package and host.framework.ServicePromemoria is an android service.
What does this error mean?
Application Not Responding (ANR) errors are triggered when the UI thread of the application is not responding for more than 5 seconds. You can read more about ANRs and diagnosing ANRs in the Android documentation.
In Android, application responsiveness is monitored by the Activity Manager and Window Manager system services. Android will display the ANR dialog for a particular application when it detects one of the following conditions: No response to an input event (such as key press or screen touch events) within 5 seconds.
If your app stops responding, users get a dialog that allows them to wait or close the app. When these dialogs appear, they're known as "Application not responding" errors (or ANRs). ANR data is available in Play Console only.
This means that your service is doing a rather long operation (most ANRs are from operations greater than 5 seconds) and is doing it on the UI thread. This could be a network task, or a database task, or some other long operation.
You can fix this by running the task in a service off the main UI thread, by using a Thread or an AsyncTask.
Infact, you can directly start your service into a new thread as follows:
Thread t = new Thread(){
public void run(){
getApplicationContext().bindService(
new Intent(getApplicationContext(), YourService.class),
serviceConnection,
Context.BIND_AUTO_CREATE
);
}
};
t.start();
Also, cache the value returned by bindservice, if any, if you require it for later use.
Although there is an accepted answer but I want do add something additional here .The reason "Application Not Responding (ANR) executing service android" is that your Service does not finished it's lifecycle call (like onCreate) during the timeout . and the default timeout for a normal service is 20s . if you need an block operate in a Servcie onCreate you need start a new Thread or you can just use the IntentService .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With