Reputation: 755
I get an weird error that saids "No enclosing instance of the type MainActivity is accessible in scope" I'm not sure how to deal with this. The error is specifically on MainActivity.this
. What happens is, I call on other classes to work in the background and I need to display a dialog at a certain point to interrupt the user to replace some files, to do an update. How can I go about setting up a dialog either through another class like I'm doing or is there another way maybe a broadcast receiver maybe?
This is my attempt to activate the dialog in another class
public class UnZip
{
public static void startzip(String pathzip, String folderpath)
{
File zipFile = new File(pathzip);
Log.d(TAG, "INSDIE of startzip path is " + zipFile);
if(isZipValid(zipFile))
{
MainActivity.mProgressDialog = new ProgressDialog(MainActivity.this);
MainActivity.mProgressDialog.setMessage("Please Wait while updating...");
MainActivity.mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
MainActivity.mProgressDialog.setCancelable(false);
MainActivity.mProgressDialog.show();
Log.d(TAG, "Made it to StartZIp");
new UnZipTask().execute(pathzip, folderpath);
}
else
{
Log.d(TAG, "Made it to StartZIp FALSE");
Toast.makeText(MainActivity.this, "Zip related error", Toast.LENGTH_SHORT).show();
}
}
}
Upvotes: 1
Views: 211
Reputation: 93561
MainActivity.this only works if you're in an inner class of MainActivity. If you're in MainActivity itself, just use this. If you're in another class entirely, you need to pass it an instance of a Context (usually the activity you're in) and pass that instead.
Upvotes: 2