-2

I am getting a ANR while binding a service from another application. The Anr is "Timeout executing service". Below is the log-

App.class :-

onCreate {
//code
}

Service.class

Add some code here for reference

Logs :-

11-11 10:15:24.880 2690 2754 I ActivityManager: Start proc 5187:com.xxxx.yyyy.myapp/u0a36 for service com.xxxx.yyyy.myapp/.speechrecognition.MyOwnService
11-11 10:15:27.279 2690 3965 V ActivityManager: >>> EXECUTING create of ServiceRecord{9df34f9 u0 com.xxxx.yyyy.myapp/.speechrecognition.MyOwnService} in app ProcessRecord{dd89a9f 5187:com.xxxx.yyyy.myapp/u0a36}
11-11 10:15:27.281 2690 3965 V ActivityManager: >>> EXECUTING bind of ServiceRecord{9df34f9 u0 com.xxxx.yyyy.myapp/.speechrecognition.MyOwnService} in app ProcessRecord{dd89a9f 5187:com.xxxx.yyyy.myapp/u0a36}
11-11 10:15:46.892 5187 5187 D Myapp: onCreate()
11-11 10:15:47.281 2690 2754 W ActivityManager: Timeout executing service: ServiceRecord{9df34f9 u0 com.xxxx.yyyy.myapp/.speechrecognition.MyOwnService}
11-11 10:15:47.452 2690 3210 V ActivityManager: <<< DONE EXECUTING ServiceRecord{9df34f9 u0 com.xxxx.yyyy.myapp/.speechrecognition.MyOwnService}: nesting=2, inDestroying=false, app=ProcessRecord{dd89a9f 5187:com.xxxx.yyyy.myapp/u0a36}
11-11 10:15:47.453 2690 3232 V ActivityManager: <<< DONE EXECUTING ServiceRecord{9df34f9 u0 com.xxxx.yyyy.myapp/.speechrecognition.MyOwnService}: nesting=1, inDestroying=false, app=ProcessRecord{dd89a9f 5187:com.xxxx.yyyy.myapp/u0a36}

Here we see that the time difference between "ActivityManager: >>> EXECUTING bind of ServiceRecord" and "Myapp: onCreate()" ( which is 1st line is of Myapp ) is almost 19 seconds. Please note My application "Myapp" has not been created while bind request of its service "MyOwnService" done. Problem is myapplication has just starts to initialize when 19 seconds already over.

What could be the reason that ActivtyManager/ActiviyService of Android is taking too much time to launch my application.?

Debabrata
  • 1
  • 1
  • 2

2 Answers2

0

ANR’ in Android is ‘Application Not Responding.’ Heavy task in the main ui thread. Use a background task to fix this problem.

You can find all you need in this article

Firas Chebbah
  • 415
  • 2
  • 12
  • 24
0

You need to create a new thread in the service's onStartCommand method.

Here is an example of a method to call in onStartCommand. all you need to do is to pass it a Runnable with the service's logic.

orimen
  • 571
  • 4
  • 11
  • This is a bind service. onStartCommand has not been overridden. Please note myapplication has just starts to initialize when 19 seconds already over. – Debabrata Jan 02 '20 at 13:38