stackcircle
stackcircle

Reputation: 1

Preventing App From Closing When Pressing Home

Due to the unpredictable nature of various Android implementations across devices my music app on some devices will stay open and run in the background and others it gets killed by the OS. I was wondering whether there is an all in one solution to keep the app running when home is pressed? At the moment I press home, a notification is sent and the music player should minimize but keep playing but it doesn't on the Sony Xperia T yet does on the LG Optimus 2X. I've tried creating a Service but its not an option due to no GUI.

Note: I'm trying to do something like what the BBC iplayer does but I can't work out how they've managed to keep the player running.

Upvotes: 0

Views: 150

Answers (2)

Steve TR
Steve TR

Reputation: 1

stackcircle - the answer really is as per Kuffs response ...

The Service plays the music.

The UI communicates with the service (via one of a number of methods, close binding, Binding/Messages, Broadcast Receivers, etc) to tell the service what to do, and to get info back from the service.

The Service can also present its own controls (such as the standard media player when backgrounded). plus 1 or more notifications, which can be non-clearable if required, by use of the NotificationManager.

Service is definitely the way forward (even if debugging can take more effort - Debug Logging is your friend :) )

Upvotes: 0

Kuffs
Kuffs

Reputation: 35651

You would use a service to play your music.

Your UI would communicate with the service and would be independent from it.

e.g Your UI could tell the service to play a different track.

You cannot force any Activity to stay resident once it is no longer in the foreground.

http://developer.android.com/guide/components/services.html#Foreground

Upvotes: 1

Related Questions