The app I'm coding checks wether there is a special ZIP-File in a Directory under /sdcard and starts to download and unzip it if not. The download and unzip works finde, even with subdirectories. But I need to restart the App when it's done - and that does not work.
At first I have a special Activity "PreMainActivity.java" just for restart purposal:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class PreMainActivity extends Activity
{
/**
*
*/
public static Boolean ENABLE_RESTART = false;
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
PreMainActivity.ENABLE_RESTART = true;
restartMain();
}
@Override
public void onRestart()
{
super.onRestart();
restartMain();
}
/**
*
*/
public void restartMain()
{
if (PreMainActivity.ENABLE_RESTART == true)
{
final Intent mainIntent = new Intent(this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
finish();
}
else
{
finish();
}
PreMainActivity.ENABLE_RESTART = false;
}
}
then I got some code within the DownloadFile.java
@Override
protected void onPostExecute(final String result)
{
MainActivity.mProgressDialogDownload.dismiss();
PreMainActivity.ENABLE_RESTART = true;
final Intent i = new Intent(MainActivity.this, PreMainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
}
As far as I have researched I need to pass the context of my MainActivity to the DownloadFile.java - but I still have no clue how. Can anyone gibe me a hint how to pass the context to a AsyncTask in a separate file within the same package? Or any other hint how to restart the whole app after a AsyncTask has finished ?