I would like to find a solution on how to stop the music when user go back to the Main Activity.
My code is below, user can go back to the Activity A as usually but the music still play from Activity B.
I have the second Activity as the code below:
Layout A
<Button
android:id="@+id/buttonUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Song" />
Java of Activity A
public class MySongActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.buttonUrl);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(context, WebViewActivity.class);
startActivity(intent);
}
});
}
}
Layout B
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none" />
Java of Activity B
public class WebViewActivity extends Activity {
WebView mWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist);
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.setWebViewClient(new HelloWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.loadUrl("http://m.orkun2u.com/msopheap/song/mysongs.htm");
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Kindly please help me. I do appreciate for your help.
Note:
I tried all the way that Google it but still doesn’t stop the music.
just one more thing about what Padma Kumar said. the way to stop is to use the
dismissfunction.updated: chenged the function from
dismiss()todestroy(), for more: read here: http://developer.android.com/reference/android/webkit/WebView.html