Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7994053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:02:11+00:00 2026-06-04T14:02:11+00:00

I am program Music Play in WebView getting link from my website. I want

  • 0

I am program Music Play in WebView getting link from my website.

I want my WebView activity kept with Status Bar Notification when user pressed Home Button. Please help give me some way.

My Code in WebView:

public class playlist extends Activity {
private WebView mWebView;
MediaPlayer myMediaPlayer;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playlist);

    mWebView = new WebView(this);

    mWebView = (WebView) findViewById(R.id.playlist);
    mWebView.setWebViewClient(new myWebClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.loadUrl("http://www.mp3skull.com/justin_bieber.html");
}

public class myWebClient extends WebViewClient  
{  
    @Override  
    public void onPageStarted(WebView view, String url, Bitmap favicon) {  
        // TODO Auto-generated method stub  
        super.onPageStarted(view, url, favicon);  
    }  
    @Override  
    public boolean shouldOverrideUrlLoading(WebView view, String url) {  
        // TODO Auto-generated method stub  
        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);
}
@Override
public void onPause() {
    mWebView.setVisibility(View.GONE);
    mWebView.destroy();
    super.onPause();
}
}

This code when user press Home Button the Music also stop because of Voide onPause(), but I need keep music playing on Status Bar Notification with correct activity. Please help me.

Regards,
Virak

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:02:12+00:00Added an answer on June 4, 2026 at 2:02 pm

    You can use onUserLeaveHint () method for playing sound when user press Home Key as doc says:

    Called as part of the activity lifecycle when an activity is about to
    go into the background as the result of user choice. For example, when
    the user presses the Home key, onUserLeaveHint() will be called, but
    when an incoming phone call causes the in-call Activity to be
    automatically brought to the foreground, onUserLeaveHint() will not be
    called on the activity being interrupted. In cases when it is invoked,
    this method is called right before the activity’s onPause() callback.

    For playing sound on Home key press use IntentService. start it in onUserLeaveHint()
    of your Activity and this service auto stop when job is finished.as:

    public class MyService extends IntentService {
    
    public MyService(String name) {
        super(name);
        // TODO Auto-generated constructor stub
    }
    public MyService () {
      super("MyService");
    }
    
    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    protected void onHandleIntent(Intent arg0) {
        // TODO Auto-generated method stub
             // PLAY SOUND HERE
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently coding some chat program and now want to play music via
I want to create a program to convert some music files from wav to
I'm a novice C# programmer and am having trouble getting music to play in
I'm building a music library program, and I want to have the ability to
Suppose I want to write a program to read movie info from IMDb, or
I want to write a program that deletes duplicate iTunes music files. One approach
I'm trying to write a simple program to play music files with Pygame. My
I have a TabBarController with two tabs and I want to play music on
I want to automate a program called Spotify from C#, the best way (I
What I want to do: I would like to program a very simple music

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.