I am coding the play mp3(Flash Embedded) in WebView(Second Activity), I can play the music in WebView as usually, but when I press back buttom to First Activity the music in Second Activity in WebView still playing, then I go to Second Activity again in WebView to stop the music but it's appear the new mp3 play list screen, I can't stop the music.
So, how can I kill the process when I press back button to First Activity(Home Screen)
Best Regards,
Virak
write this function in your class. actually this will override onpause.
#Override
protected void onPause() {
super.onPause();
finish();
}
This was the only thing that worked for me. To use the destroy() method of WebView in the onPause() lifecycle method.
#Override
public void onPause(){
super.onPause();
wView.destroy();
}
Related
A part of my code: (Problem Explanation follows)
#Override
protected void onStop() {
super.onStop();
if(mediaPlayer != null){
mediaPlayer.release();
mediaPlayer = null;
}
}
My main idea of using this was to stop playing the audio when the home button was pressed, but this doesn't seem to be happening as audio isn't stopping.
Thanks in advance.. :)
You are hooking into the Activities onStop() method to stop the audio however when you press the home button, an Activities state is being saved, and therefore the activity calls its onPause() method instead of onStop().
If you want to stop audio when the home button is pressed, I suggest moving your call to the media player that's stopping it, into the Activities onPause() method.
I have a Mediaplayer mpFond, started in my first activity. If I press the HOME, the mediaplayer is stopped, and if i press "PLAY" to go in my other activity, the sound continu (that's good). When I press the Home button in my first activity (where I started the mediaplayer), it's ok, my sound stop, but if I press the Home button in the other activity, it does not (and that's my problem).
So I just want to know if I can pass the Mediaplayer in the other activity to stop it when I press the Home button (without using Services, i'm new, so ...)
I just use that to stop the sound when I press the Home button :
#Override
public void onPause()
{
super.onPause();
if(this.isFinishing()){
mpFond.stop();
}
}
#Override
public void onStop(){
super.onStop();
if(this.isFinishing()){
mpFond.stop();
}
}
For some reasons, there is no way you can pass the MediaPlayer object to another activity through intent. Maybe it is because activity only passes Parcelable or Serializable objects. But I just discovered another way. To pass MediaPlayer to another activity you need to
1- create the MediaPlayer inside your application object.
2- Access the MediaPlayer from whatever activity you want and bind it over again to it.
I have written webview on which there may be youtube videos. When I start video and press home button application closes (Goes in background) and I can still hear audio. Then I had to kill task manually (Using battary-doctor now !!)
I have tried onPause() and onStop() methods and tried to call finish() but it is not working.
I saw some questions where it is written it is not possible to override home button.
What I want to do is kill the activity once home button is pressed. If android is handling killing ... fine .. but just pause the youtube video and then go to background !!!
Can someone help ??
Rather than killing the activity, you should just clear the WebView. onPause() is called when the activity goes into background, so that's where you should attempt to "unload" the WebView.
#Override
protected void onPause() {
super.onPause();
mWebView.loadUrl("about:blank");
}
try
android.os.Process.killProcess(android.os.Process.myPid());
try
#Override
protected void onStop() {
super.onStop();
onDestroy();
}
EDIT: To be honest You should not try to kill apllication at pressing home button, but pause video at that moment. OnPause() method is a place where You should do.
Hi i am developing a game using andengine. I am unable to pause the music when power button interrupt. In manifest file I added:
android:configChanges="orientation|keyboard|keyboardHidden"
code- onPause and onResume methods
protected void onPause() {
if(menumusic!=null)
menumusic.pause();
super.onPause();
this.mEngine.onPause() ;
}
protected void onResume() {
if(menumusic!=null)
menumusic.resume();
super.onResume();
this.mEngine.onResume();
}
Problem is when power button is pressed onPause() method is calling and immediately onResume() is calling.
Plz help me.
try this ..hope this may help u
use onWindowFocusChanged to help resume the game. it works and music does not resume until u r back in the game:
http://www.andengine.org/forums/gles2/onresume-being-called-when-device-should-be-paused-t8748.html#p42961
How stop playing audio when click back button ? or exit application it's keeping playing on background
I made application has 2 activities first Main welcome activity you click on start button show second activity which contain grid view for multiple images when click on an image start play different sound , but when click back button switch to Main activity but sound keep playing !! and if click home also keep playing?
how to stop it ?
Tell it to stop in the onPause() of the Activity.
#Override
public void onPause() {
super.onPause();
if (player.isPlaying()) {
player.stop();
}
}