Android Service - stop the service from settings App - android

I have developed a music player application,which has a service(AudioPlayerService) which will be running in the background.Service will be started when play button is pressed. It will run in the background even though application goes to background.
Playback can be stopped by bringing the app to foreground and press the stop button, which makes the music to stop and stops the AudioPlayerService too. everything works fine.
Otherway i can use the Force Stop from Settings app (Settions->Application->Downloaded->Select the App->Press Force Stop Button).
I am able to stop the application and music also stopped playing.
But If i use Stop button from Settings App (Settings->Applications->Running->Select the App -> Press Stop), application is terminated and my app is removed from the running app list, but music is still playing in the background.
I am not sure why Running Tab Stop Button does not stop the music.
Any one help me if i need to handle anything in my service to class to stop the playback.
I am testing in Samsung Galaxy S2 with Android 4.0.3
Thanks
Sasikumar JP

On the onDestroy override method of your service use your mediaplayer object to stop the media from playing.
#Override
OnDestroy{
mediaplyer.stop();
}

Related

Service stopping after some time Android 10

I'm trying to create service that plays music in background. Everything works fine, except that the service is stopping after some time when the phone is locked. To be exact - my service logic looks like that:
after pressing start it plays music (playNext function is called), when the music ends the playNext function is called again. For some time it works perfectly, but when the phone is locked after a few songs, the song is ending and the next one is not starting until I press any physical button to wake up the phone.
The service is being run in foreground with a Notification, onStartCommand returns START_STICKY.
I'm using Android 10, my phone is Xiaomi Mi A2 lite.
As far as I remember issues like that weren't happening to me before - is it some new 'feature' in Android10 to workaround? And how to do that if yes? Or maybe it's my phone model problem and nothing can be done here?
It seems I have found a reason.
The problem is with my phone. After upgrade to android 10 there are some bugs (for example different music players are spontaneously pausing music).

how to stop musicplayer application from my application

I am trying to make an application that stops the music player when the button is pressed?
everything works fine but i am not able to close the music player application? any suggestion or help....

What method is called when i change activities?

I have a MediaPlayer that keeps playing when I change activities and when I even click the physical Home button on my phone. How can I make it so that the MediaPlayer keeps playing when I change activities yet stops playing when I click the Home screen button?
You can use a service. that keeps running the background.
the service is similar to normal activities but they run in background and dont have a user interface

Android: Background music is playing while lock screen is on

If my activity is running in the foreground and the display is turned off and then turned back on again the background music starts to play again before the screen is unlocked. The background music is paused in onPause() and continues to play in onResume(). So when the app is pushed to the background the music stops.
Is there a way to prevent the music from playing while the lock screen is on?
//André
Take a look over here.This will solve your problem.
https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

Phonegap app closing problem

I am using phonegap with Android.I have a sound playing repeatedly with a timer.If I close the app the sound continues to play.Is there a app closing handler or something I could use to make the sound stop when the app exits.
I am using a Samsung Captivate(Galaxy S).If I press the back button the sound stops when the app exits.But if I press the home button then the sound just goes on forever when the app exits.
Thanks
You can catch the backbutton and stop the music playing and then close the app.
It's however not possible (as far as i know) to catch the close event.
http://wiki.phonegap.com/w/page/29494136/Android-Back-Button-Handler
Here is how to do that.

Categories

Resources