Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

demo gets killed in the background

Rank

Total Posts: 6

Joined 0

PM

I have a problem with the Antplusdemo.

If it is in the background, if I start another program or get back to the homescreen, the app gets killed after a while.

The log says this:

D/ANTApp (10517): enter onReceive: com.dsi.ant.intent.action.ANT_RX_MESSAGE_ACTION
D/ANTApp (10517): onReceive: ANT RX MESSAGE
D/ANTApp (10517): Rx:[03][40][00][01][02]
D/ANTApp (10517): enter onReceive: com.dsi.ant.intent.action.ANT_RX_MESSAGE_ACTION
D/ANTApp (10517): onReceive: ANT RX MESSAGE
D/ANTApp (10517): Rx:[03][40][00][01][02]
D/ANTApp (10517): enter onReceive: com.dsi.ant.intent.action.ANT_RX_MESSAGE_ACTION
D/ANTApp (10517): onReceive: ANT RX MESSAGE
D/ANTApp (10517): Rx:[03][40][00][01][02]
I/ActivityManager( 233): No longer want com.dsi.ant.statenotifier (pid 10529): hidden #16
I/ActivityManager( 233): No longer want com.dsi.ant.service.socket (pid 9743): hidden #17
I/ActivityManager( 233): No longer want com.dsi.ant.antplusdemo (pid 10517): hidden #18
D/AntHal ( 233): failed to read from client=253
I/bluedroid( 233): Stopping hciattach deamon
W/ActivityManager( 233): Scheduling restart of crashed service com.dsi.ant.service.socket/.AntRadioService in 5000ms
I/bluedroid( 233): Stopping hciattach deamon
D/AntHal ( 233): client 253 closed
D/AntHal ( 233): waiting for new client
I/WindowManager( 233): WIN DEATH: Window{2b3c8ae0 com.dsi.ant.antplusdemo/com.dsi.ant.antplusdemo.ANTPlusDemo paused=false}
I/ActivityManager( 233): Start proc com.dsi.ant.service.socket for service com.dsi.ant.service.socket/.AntRadioService: pid=10815 uid=10054 gids={}
D/dalvikvm( 623): GC_EXPLICIT freed 72K, 49% free 2814K/5511K, external 1685K/2133K, paused 78ms
I/ANTRadioService(10815): System connection: Local Socket. Service runs forever
W/ActivityManager( 233): Unable to start service Intent { act=com.dsi.ant.server.IAntHal }: not found
I/AntRadioServiceStarter(10815): Trigger start action received
D/ANTSocketManagerThread(10815): start: starting
I/ANTSocketManagerThread(10815): ANT initialising...
D/AntHal ( 233): got client 252
I/AntHal ( 233): client=252 starting...
W/ActivityManager( 233): finishReceiver called but no pending broadcasts
I/bluedroid( 233): Starting hciattach daemon
D/ANTSocketManagerThread(10815): rxThread: Connected
I/ANTSocketManagerThread(10815): ANT Version: AOV1.08B00��
I/ANTSocketManagerThread(10815): ...ANT initialised. Enabling...
I/ANTSocketManagerThread(10815): ...ANT enabled
D/dalvikvm(10103): GC_EXPLICIT freed 847K, 57% free 3209K/7303K, external 1685K/2133K, paused 41ms

I read that it is a problem with a service that is in the background and could be started in the foreground, but I am not sure how.

Do you know a way how I can run the app indefinitely?      
Avatar
RankRankRankRank

Total Posts: 129

Joined 2010-11-30

PM

The ANT Radio Service will have the same priority as any application that is using it, so if your app is in the background the Android system will see it as ok to destroy both your app and the service if it needs system resources.

If your application needs to keep running to record ANT data while in the background, it should implement a Service and use startForeground() to run it as a foreground service.

Details on Services are available on the Android Developers site:
http://developer.android.com/reference/android/app/Service.html

plus there is an example for a Foreground Service implementation:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ForegroundService.html      
Avatar
RankRankRankRank

Total Posts: 296

Joined 0

PM

Did you make yourself familiar with the basics of Android app development?
Due to resource restriction, Android requires apps to be very "cooperative". This includes apps to be suspended, free their resources when backgrounded and even be killed when necessary.

So what you ask for shouldn't be done on Android if there's not a VERY good reason for it.

Cheers,
OMB      
Rank

Total Posts: 6

Joined 0

PM

thanks the startforeground example is working and does exactly what I want