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

  • SEARCH
  • Home
  • 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 1087435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:56:20+00:00 2026-05-16T22:56:20+00:00

I am using an AsyncTask to fetch the ring tone for a contact when

  • 0

I am using an AsyncTask to fetch the ring tone for a contact when my application starts, it works fine until after my Activity closes a couple of times during the AsyncTask, after this happens the AsyncTask will only ever get to onPreExecute() and never doInBackground, so I can never fetch the ringtone then until either a force stop or device restart.

Can anyone explain why this might be happening?

Why the AsyncTask would get to onPreExecute but then never run doInBackground()?

Here is my code: (Following the Shelves source code)

public void getRingTone(){
Log.d("cda", "Into getRingTone");  
if (audio_service.getStreamVolume(AudioManager.STREAM_RING) > 0) { 
    if(aRingTone != null){ 
        oRingtone = RingtoneManager.getRingtone(this, 
              Uri.parse(aRingTone));
    }
    this.setVolumeControlStream(AudioManager.STREAM_RING);

 }
}

private void saveRingToneTask(Bundle outState) {
final SelectRingtoneTask task = srtt;
if (task != null && task.getStatus() != AsyncTask.Status.FINISHED) {
    task.cancel(true);

    srtt = null;
}
}

private void restoreRingToneTask(Bundle savedInstanceState) {

        srtt = (SelectRingtoneTask) new SelectRingtoneTask().execute();

}

private void onAddRingTone() {
srtt = (SelectRingtoneTask) new SelectRingtoneTask().execute();

}

private void onCancelAddRingTone() {
if (srtt != null && srtt.getStatus() == AsyncTask.Status.RUNNING) {
    srtt.cancel(true);
    srtt = null;
}
}

—

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
restoreRingToneTask(savedInstanceState);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (isFinishing()) {
    saveRingToneTask(outState);
}
}

private class SelectRingtoneTask extends AsyncTask<String, Void, Void> {


@Override
public void onPreExecute() {
    Log.d("cda", "Into selectRingToneTask - onPreExecute() - " + selectRingtoneFinished);
    findViewById(R.id.answercallimage).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                    serviceBinder.answer(lineId);
                    onCancelAddRingTone();
                } catch (RemoteException e) {

                    e.printStackTrace();
                }
        }
});


    findViewById(R.id.declinecallimage).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            mNotificationManager.cancel(2);
            callConnected = false;

            try {
                serviceBinder.reject(lineId);
                onCancelAddRingTone();
            } catch (RemoteException e) {

                e.printStackTrace();
            }
        }
});

}



public Void doInBackground(String... params) {
    Log.d("cda", "Into selectRingToneTask - !!!!!!!!!!!!!!!");
    if(!this.isCancelled()){
    getRingTone();
    }
    return null;

}

@Override
public void onCancelled() {
    Log.d("cda", "Into selectRingToneTask - onCancelled() - ");
}

@Override
public void onPostExecute(final Void unused) {
     selectRingtoneFinished = true;
       Log.d("cda", "Into selectRingToneTask - onPostExecute - " + selectRingtoneFinished);
       if(oRingtone != null && playRingTone){
            Log.d("cda", "Into getRingTone - PLAY RINGTONE");  
           oRingtone.play();
        }
}
}

And onAddRingtone() is used in onCreate and onCancelRingTone() is used in onDestroy() as well as where you can see if in the code above.

I have spent 3 days on this and I haven’t been able to find a solution? Am I taking the wrong approach? Using cancel wrong? Is there a bug?

  • 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-16T22:56:20+00:00Added an answer on May 16, 2026 at 10:56 pm

    I believe what is happening is that your AsyncTask has a handle on the old activity, when you create a new one in the middle of the task you have essentially leaked your AsyncTask. The DroidFu library has a workaround for this by keeping track of the active activity in an overridden Application class and an overridden AsyncTask dependent on the Application. Luckily its open source so you can see how they do it. Additional Info

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

Sidebar

Related Questions

I'm using AsyncTask s to fetch data in response to the user pressing a
I am trying to create HTTP connection using AsyncTask class. Is it possible to
I don't understand why I'm getting this error. I'm using AsyncTask to run some
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button

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.