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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:36:02+00:00 2026-05-24T15:36:02+00:00

I want to preform a Toast when a background task is completed, just to

  • 0

I want to preform a Toast when a background task is completed, just to let the user know that it’s finished.

I’ve made a new class for my asyncTask, but I cannot use getApplicationContext() within this class.

I’m using task.execute(getTempFile(this), getApplicationContext()); to run the tasks. getTempFile returns a File object, and I was trying to pass the context as a Context object.

My Task class has three variables, AsyncTask<Object, Integer, Integer>, so the context is in the second object. However, this crashes the application.

public class LocationActivity extends Activity implements LocationListener {
    protected void handleImage(Bitmap thumbnail) {
        PushDataToServer task = new PushDataToServer();
        task.execute(getTempFile(this), getApplicationContext());
    }
}


public class PushDataToServer extends AsyncTask<Object, Integer, Integer> {

    Context context;

    @Override
    protected Integer doInBackground(Object... params) {
        // TODO Auto-generated method stub
        this.context = (Context) params[1];
        File file = (File) params[0];
        return null;
    }

    protected void onPostExecute(String result) {
         Toast toast = Toast.makeText(this.context, "All done!", Toast.LENGTH_SHORT);
         toast.show();
    }

}
  • 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-24T15:36:02+00:00Added an answer on May 24, 2026 at 3:36 pm

    Pass a Context object into the AsyncTask‘s constructor.

    Sample code:

    public class MyTask extends AsyncTask<?, ? ,?> {
        private Context mContext;
    
        public MyTask(Context context) {
            mContext = context;
        } 
    }
    

    and then, when you are constructing your AsyncTask:

    MyTask task = new MyTask(this);
    task.execute(...);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List of Tasks that a user can preform. Each one will
It seems that every time I want to perform a db query, I have
I have a navigation app that has many screens the user navigates to. A
I want to perform a series of operations on elements that matched the name
I want to be able to off the user a choice of options and
I have an Android app where I want to offer the user the choice
I have a ArrayList that contains values in the form [ann,john]. I want to
I want to perform this date check: The date entered by the user should
I have an animation that I want to happen before an action is called.
I want to perform 4 'if' statements if it can be phrased like that;

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.