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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:40+00:00 2026-06-12T09:15:40+00:00

The app I’m coding checks wether there is a special ZIP-File in a Directory

  • 0

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 ?

  • 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-06-12T09:15:41+00:00Added an answer on June 12, 2026 at 9:15 am

    You will need to Create a constructor of the AsyncTask to pass Current Activity Context as:

       public Context ctx;
    
        public Your_AsyncTask_Class_Name (Context context){
            super();
            this.ctx=context;
    
        }
      ......
    @Override
    protected void onPostExecute(final String result)
    {
    
        MainActivity.mProgressDialogDownload.dismiss();
        PreMainActivity.ENABLE_RESTART = true;
        final Intent i = new Intent(ctx, PreMainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(i);
    }
    

    and from Activity you can pass context as:

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

Sidebar

Related Questions

My app will no longer run under Snow Leopard, even though it was originally
The app I am working on is supporting android 2.3 upwards. As the download
My app is saving some images on the SD Card, in the AppImages directory
my app has a submit feedback form. Is there a way to can capture
app.get(/:name?/:group?, function(req, res){... is matching files that are in my public directory. So if
My app connects to a Bluetooth sensor then starts updating the UI based on
App: C#, .NET4, Windows 7 When an app starts up, it gets a copy
My app displays grouped static UITableViews in different screens. Is there anyway of using
App I'm working on uses ARC. I wanted it to process large files, so
/app/config/parameters.ini [parameters] database_driver = pdo_mysql database_host = localhost database_port = database_name = my_dbname database_user

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.