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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:27:50+00:00 2026-05-24T20:27:50+00:00

My question is how to pass parameter to AsyncTask dynamically. How I do this?

  • 0

My question is how to pass parameter to AsyncTask dynamically. How I do this?

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.daily_download);

    SharedPreferences myPrefs = this.getSharedPreferences("myLogedPrefs",MODE_WORLD_READABLE);
    strBusinessUnit = myPrefs.getString("BusinessUnit", "");
    strExecutive = myPrefs.getString("Executive", "");
    strTerritoryCode = myPrefs.getString("TerritoryCode", "");

    tableListGrid = (GridView)findViewById(R.id.dailydownloadgrid);
    tableListGrid.setAdapter(new TableListImageAdapter(this));
    tableListGrid.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position,long id) {
            if (position == 0) {
                dailyDownTable = "LoadTarget";
                jsonFilter = "Target1";
                new DailyDownldAsyncTask().execute();
            }
        }
    });
}



    public class DailyDownldAsyncTask extends AsyncTask<Void, Integer, Void> {
        // private final ProgressDialog dialog = new ProgressDialog(DailyDownloadActivity.this);
         int myProgress;

        @Override
        protected void onPostExecute(Void result) {

            //if (this.dialog.isShowing()) {
            //  this.dialog.dismiss();
            //}
            //Toast.makeText(DailyDownloadActivity.this,"Download successfully",Toast.LENGTH_SHORT).show();

        }

      @Override
      protected void onPreExecute() {

         // this.dialog.setMessage("Downloading Table Data.......");
         // this.dialog.show();
         // myProgress = 0;
      }

      @Override
      protected Void doInBackground(Void... params) {
          new DownlaodTableActivity().loadDailyDownloadData(dailyDownTable,jsonFilter,strBusinessUnit, strBusinessUnit,strTerritoryCode);
       return null;
      }

      @Override
      protected void onProgressUpdate(Integer... values) {
         // dialog.setProgress(values[0]);
      }
 }

I commented ‘ProgressDialog ‘ & run the code also I got error
Here loadDailyDownloadDatadailyDownTable,jsonFilter,strBusinessUnit, strBusinessUnit,strTerritoryCode) method i want to pass parameter.

When I run this code I got error :

     08-19 09:22:15.521: ERROR/AndroidRuntime(457): FATAL EXCEPTION: AsyncTask #2
08-19 09:22:15.521: ERROR/AndroidRuntime(457): java.lang.RuntimeException: An error occured while executing doInBackground()
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.lang.Thread.run(Thread.java:1019)
08-19 09:22:15.521: ERROR/AndroidRuntime(457): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at android.os.Handler.<init>(Handler.java:121)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at android.app.Activity.<init>(Activity.java:680)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at com.xont.controller.syn.DownlaodTableActivity.<init>(DownlaodTableActivity.java:62)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at com.xont.controller.admin.DailyDownloadActivity$DailyDownldAsyncTask.doInBackground(DailyDownloadActivity.java:83)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at com.xont.controller.admin.DailyDownloadActivity$DailyDownldAsyncTask.doInBackground(DailyDownloadActivity.java:1)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-19 09:22:15.521: ERROR/AndroidRuntime(457):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

Please help me ….

Thanks in advance

  • 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-24T20:27:51+00:00Added an answer on May 24, 2026 at 8:27 pm

    Seem you need to read the document for AsyncTask more first. http://developer.android.com/reference/android/os/AsyncTask.html

    Crashing problem:

    Keep in mind that doInBackground will be executed in background thread. The crashing problem you are seeing is that DownlaodTableActivity is instantiated inside a background thread, which is IMPOSSIBLE in Android framework. (Has nothing to do with parameters passing by the way) All activities must be instantiated in the main UI thread. The Looper.prepare() will be called if you have instantiated it in UI thread.

    Solution: move loadDailyDownloadData to a different class that does not depend on DownlaodTableActivity. If you want to the UI to be updated in DownlaodTableActivity, do it in UI thread after you download the data.

    Parameter passing:

    strBusinessUnit = myPrefs.getString("BusinessUnit", "");
    strExecutive = myPrefs.getString("Executive", "");
    strTerritoryCode = myPrefs.getString("TerritoryCode", "");
    ... ...
    new DailyDownldAsyncTask().execute(dailyDownTable, jsonFilter, strBusinessUnit, strExecutive, strTerritoryCode);
    ... ...
    
    public class DailyDownldAsyncTask extends AsyncTask<String, Integer, Void> {
            // private final ProgressDialog dialog = new ProgressDialog(DailyDownloadActivity.this);
             int myProgress;
    
    ... ...
    
          @Override
          protected Void doInBackground(Void... params) { 
    dailyDownloadData(params[0],params[1],params[2], params[3],params[4];
           return null;
          }
    ... ...
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is regarding getopt function in php. I need to pass two parameter
Following this question - Pass Method as Parameter using C# and some of my
This question builds off of a previously asked question: Pass by reference multidimensional array
Expanding this question on how I learnt to pass from problem description to code
This is a follow-up question to ASP.NET How to pass container value as javascript
This is probably more of a JavaScript question but I'd like to pass another
I have a rather silly question, I need to pass a parameter from one
This is a follow up question to this question: Lambda how can I pass
This is an extension question of PHP pass in $this to function outside class
The question I have is exactly same in requirement as How to pass mouse

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.