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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:08:49+00:00 2026-06-04T23:08:49+00:00

I have a simple AsyncTask whose doInBackground() calls a function fn1 which in turn

  • 0

I have a simple AsyncTask whose doInBackground() calls a function fn1 which in turn simply calls another fn2. The result is a “Activity has leaked window” crash! When I call fn2 directly from doInBackground() everything works fine. Does that mean in a thread one cannot have more than 1 level of fn calling?( Thread-> fn1->fn2)

I am new to Java and android, so please bear with me if that is a basic question! Thnx.

My code algo is something ike this :

MyActivity:

MyLibrary myLib;

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.myXML);

    myLib = new MyLibrary(MyActivity.this);
    new myTask().execute();

}

private class myTask extends AsyncTask<Void, Void, Void> 
{

    @Override
    protected void onPreExecute() {
        progressDialog = ProgressDialog.show(MyActivity.this, "", "Fetching Data...");
    }
    @Override
    protected Void doInBackground(Void... params) {

            myLib.fn1();        
            return null;

    }

    @Override
    protected void onPostExecute(Void result) {

        progressDialog.dismiss();
    }
}

MyLibrary :

Context ctx;
String iVar;

public MyLibrary(Context context){
    this.ctx = context;
}

public void fn1()
{

  fn2();
  Log.d("TAG", "Function 1";
}

public void fn2()
{
   iVar = "100"; 
   Log.d("TAG", "Function 2";
}
  • 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-04T23:08:51+00:00Added an answer on June 4, 2026 at 11:08 pm

    Add the following in your Activity’s code:

    @Override
    protected void onPause() {
        super.onPause();
    
        if(progressDialog != null)
            progressDialog.dismiss();
    }
    

    It will dismiss the dialog window in case you move away from activity.

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

Sidebar

Related Questions

I have a simple activity in which I start an AsyncTask with a button
I have an asynctask of which's onPostExecute i am calling a function to show
I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package in which On Error event handler I have created
I have a very simple AsyncTask implementation example and am having problem in testing
I have a very simple Activity to record audio using MediaRecorder . Basic start/stop
i have developed a simple AsyncTask class that takes Handlers as its parameters and
I have simple user registration form. In which i am puting city as a
I have created a simple async operation which is being kicked of when the
So, my application have one activity ProjectActivity as a home, which contains 3 fragments

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.