tags:

views:

60

answers:

3

I have this code fragment:

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 execute this thread as

new ExportDatabaseFileTask().execute();

As you see I use a ctx as Context variable in the new ProgressDialog call, how do I pass a context to the call method?

to this one:

new ExportDatabaseFileTask().execute();*
A: 

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

Roflcoptr
A: 

I found the 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);
        }
Pentium10
yes ok that also works.... i thought the static keyword is necessary and in static classes you can't define constructors.
Roflcoptr
actually I need the static keyword in front of the class name, otherwise can't recognize it, but I make a new instance of it.
Pentium10
A: 

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

grmn.bob