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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:26:52+00:00 2026-06-05T16:26:52+00:00

i know it should be context. what exactly is a context though. usually when

  • 0

i know it should be context.
what exactly is a context though.
usually when i create a dialog in a class
i do something like this:

final Dialog dialog = new Dialog(this);

but now i am trying to create a dialog in an AsyncTask<>
therefore i cannot do the above cause AsyncTask isn’t a context evidently.
the AsyncTask is a class in itself, which is to say its not a subclass right now.

public class popTask extends AsyncTask<Void, Void, String> {

Context con =

@Override
protected void onPostExecute(String result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);

    final Dialog dialog = new Dialog(con);
    dialog.setContentView(R.layout.custom);
    dialog.setTitle("New & Hot advertise");

    // set the custom dialog components - text, image and button
    TextView text = (TextView) dialog.findViewById(R.id.text);
    text.setText("Android custom dialog example!");
    ImageView image = (ImageView) dialog.findViewById(R.id.image);
    image.setImageResource(R.drawable.yoda);

    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
}


@Override
protected String doInBackground(Void... params) {
    // TODO Auto-generated method stub
    return null;
}



}
  • 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-05T16:26:53+00:00Added an answer on June 5, 2026 at 4:26 pm

    The following are the two ways you can send your context from the activity where you are executing your AsyncTask:

    popTask pTask = new popTask(mContext); //OR
    pTask.execute(mContext);
    

    In your popTask create a private variable where you can set your context.

    In the first option you need to have a constructor for your class popTask where you are accepting a context.

    For the second option if you are not passing anything meaningful to the function doInBackground() you can change the following line:

    public class popTask extends AsyncTask<Object, Void, String>
    
    protected Object doInBackground(Object... params) {
    this.mContext = (Context) params[0];
    

    }

    you will receive the context object in the doInBackground() which you can set in the private Context variable of the popTask class and then access it in the doInBackground() function.

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

Sidebar

Related Questions

I know I should write this in Vb.net but for my own reasons I'm
I know I should be able to solve this myself, but I've been banging
I know this should be a basic question but I am hitting a brick
I know I should do my homework on my own but I simply can't
I know you should use a StringBuilder when concatenating strings but I was just
I know it should be a fairly easy thing to do but for some
I know there are other questions on the forum regarding this but found ho
There is a lot of confusion about this and I'd like to know, what
I have code that looks like this: <h4 class=tableTotals>Total Selected: R<div id=bankTotal>##,##</div></h4> The output
First you should know I have looked into many questions and none of them

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.