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 6821835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:35:32+00:00 2026-05-26T21:35:32+00:00

I have an AsyncTask that is executed before I move on to the next

  • 0

I have an AsyncTask that is executed before I move on to the next Activity. Inside this AsyncTask, I have a MediaPlayer.

 protected void onPause() {
           stopProgress();
           Log.i(TAG, "onPAUSE");
           try  {
           } finally {
           // If we allocated a player, then cleanup after it
           if (player != null) {
               player.reset();
               player.release();
               player = null;
               Log.d(TAG,"end of player cleanup");
                            }
            }
            super.onPause();
         }

Use Scenario:

  1. Click play button in Activity 1
  2. Move on to Activity 2 before player even loads (log information from onPause is definitely called).
  3. While in Activity 2, player from Activity 1 plays when finished loading.
  • 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-05-26T21:35:32+00:00Added an answer on May 26, 2026 at 9:35 pm

    Nothing should happen to the AsyncTask. It will continue to run. However, this isn’t a great way to run a media player in the background (use a service for that). Your code will cancel the media player, but depending on what you have in your AsyncTask, it may still be active. You can ensure that the AsyncTask is killed by calling cancel (boolean mayInterruptIfRunning) on the task.

    If for whatever reason your MediaPlayer object is still running using the code above, then call AsyncTask.cancel(true) and override void onCancelled (Result result) and then kill the MediaPlayer from within your thread. Remember, onCancelled will only be called AFTER doInBackground returns (or you can periodically check isCancelled() to see if something has called cancel() on your thread. If you set cancel(true) then I believe it won’t bother waiting for doInBackground to finish, but of course that’s not as clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that is executed using asyncTask with a progressdialog. After this
I have this activity that class a Login class inside an onclick event. My
i have an AsyncTask that gets executed when the app starts up. on a
I have work that needs to be done in this order: In main activity:
I have a backgorund thread that extends AsyncTask and which I use in activity
I have a service, that requests another class, which launches an AsyncTask Service->Weather Class->Execute
I have a large activity that contains 100 or more buttons. But it's working
i have a bunch of actions that need to be executed in an android
I have an activity in which I display an image that is stored on
I have AsyncTask that processes some background HTTP stuff. AsyncTask runs on schedule (Alarms/service)

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.