How to pass a Context object to a stream upon call

I have this piece of code:

public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> 
{
    private final ProgressDialog dialog = new ProgressDialog(ctx);

    protected void onPreExecute();
    protected Boolean doInBackground(final String... args);
    protected void onPostExecute(final Boolean success);
}

      

I am executing this thread as

new ExportDatabaseFileTask().execute();

      

As you can see I am using ctx as Context variable in new call to ProgressDialog, how can I pass context to call method?

to that:

new ExportDatabaseFileTask().execute();*

      

+2


a source to share


3 answers


I found a way, I had to create my own constructor and lose the static stuff



        public ExportDatabaseFileTask(Context ctx) {
            super();
            this.ctx=ctx;
            dialog= new ProgressDialog(ctx);
        }

      

+5


a source


Just define a static setter method where you can pass the Context object



+1


a source


I just stumbled upon this in the Dev Guide and I believe this is exactly its purpose. android.content.ContextWrapper

0


a source







All Articles