Reputation: 848
I have a service which is also LocationListener. Upon new location event it performes some kind of network stuff which can take time; that's why it is implemented as AsyncTask.
Often I see in log on the real device:
03-29 17:02:20.847 D/dalvikvm( 235): GC_FOR_ALLOC freed 961K, 29% free 10234K/14215K, paused 26ms
03-29 17:02:20.855 I/DemoService( 555): DiyScheduer.onStart
03-29 17:02:20.855 I/ggheart ( 555): onStart
03-29 17:02:21.097 V/PhoneStatusBar( 235): setLightsOn(true)
03-29 17:02:21.121 W/IInputConnectionWrapper(11244): showStatusIcon on inactive InputConnection
03-29 17:02:21.277 I/ActivityManager( 161): Process android.process.media (pid 11298) has died.
03-29 17:02:22.058 I/ActivityManager( 161): Process com.idavydov.myapp (pid 11051) has died.
03-29 17:02:22.066 I/WindowManager( 161): WIN DEATH: Window{41b05850 com.idavydov.myapp/com.idavydov.myapp.MyActivity paused=false}
03-29 17:02:22.074 W/ActivityManager( 161): Scheduling restart of crashed service com.idavydov.myapp/.MyService in 5000ms
Usually it happens after some large application is loaded.
Is the reason for this low memory? In that case why there is no such kind of message in log?
P.S. In other question I saw explanation that the reason is that the task takes too much time. But I've added the folowing code to my AsyncTask and couldn't reproduce the crash in the emulator.
protected Boolean doInBackground(...) {
...
long time = System.currentTimeMillis();
while (System.currentTimeMillis() - time < 11 * 1000);
....
}
Thanks
Upvotes: 4
Views: 7134
Reputation: 2309
I think you mixing two things. Android doesnt allow blocking the UI thread, and it will kill your app if so. Unless you put the blocking processing and loops into the background process of AsyncTask.
Beside of this, android will kill your app without any warning when it has low memory or it identifies that your app has no effect on the user. If you want your app to stay longer, you'll need a sticky service and a good app lifecycle managment.
Upvotes: 1