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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:36:05+00:00 2026-05-29T05:36:05+00:00

I have AsyncTask and my progress in background is in infinite loop. But I

  • 0

I have AsyncTask and my progress in background is in infinite loop. But I need to stop AsyncTask when user stop my app or go back from my app (my app go to foreground). How can I do it?

Solution:

private boolean done = false;

private class CurTask extends AsyncTask<String, Void, Object> {
        protected Void doInBackground(String... args) {
            while(!done){
                DefaultCurProgress();           
                publishProgress();
            }
        }

        protected void onProgressUpdate(Void...unused) {
            textCur = (TextView)findViewById(R.id.text_cur);

            SharedPreferences myPrefs = MyActivity.this.getSharedPreferences("myPrefs", MODE_PRIVATE);
            String prefNameDefaultCur = myPrefs.getString(DefaultCur, "");

            textCur.setText(prefNameDefaultCur); 
        }
}

@Override
    public void onPause(){
        super.onPause();
        done=true;
    }

    @Override
    public void onResume(){
        super.onResume();
        done=false;
    }
  • 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-29T05:36:05+00:00Added an answer on May 29, 2026 at 5:36 am

    Declare a method within your AsyncTask that tells it to end. Something like so:

    private class CurTask extends AsyncTask<String, Void, Object> {
        private boolean done = false;
    
        public void quit() {
            done = true;
        }
    
        protected Void doInBackground(String... args) {
            while(!done){
                DefaultCurProgress();           
                publishProgress();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asynctask that reads data from a device and then I want
In my app i have a processDialog (using AsyncTask) and at doInbackground it fetches
I have a code that downloads videos from a URL. I am using AsyncTask.
I have a task which I need to run in the background in my
In my project I have a AsyncTask that fetches some JSON data from the
I currently have an asyncTask which on preexecute begins a loading bar, in background
I have an Android application which retrieves information from the web using an AsyncTask
I need to download a image in a AsyncTask and display progress in a
Possible Duplicate: Updating progress dialog in Activity from AsyncTask I am developing my first
I am trying to create downloading progress. I have my class which extends AsyncTask:

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.