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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:16:35+00:00 2026-06-14T23:16:35+00:00

I have two activities. While switching to second activity by intent, it takes 3-4

  • 0

I have two activities. While switching to second activity by intent, it takes 3-4 seconds because it has lots of components with adapters fetching data from SQLite etc. Thus, I want to show a progress dialog while switching.

I have been digging topics for this purpose and tried many of them:

1-) Using AsyncTask on the second activity. It doesn’t show the progress dialog as soon as I click on a component to switch to the second activity. It waits for 3-4 seconds and then progress dialog shows up for less then a second which is not user-friendly way.

2-) Using AsyncTask on the first activity. It shows as soon as I click on that component but the progress wheel doesn’t spin. The progress dialog freezes.

3-) Using AsyncTask onStart() method on the second activity. This results as the first way.

The code below implements the second way above, using AsyncTask on the first activity.

public void toVisitRegister(Event event) { //Switching to the second activity
    new startingThread().execute();
    Intent toVisitRegister = new Intent(MainCalendar.this, VisitRegister.class);
    startActivity(toVisitRegister);
    finish();
}

And here is the AsyncTask

public class startingThread extends AsyncTask<String, String, String> { 
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        startingProgress = new ProgressDialog(MainCalendar.this);
        startingProgress.setTitle("Visit Register");
        startingProgress.setMessage("Initializing...");
        startingProgress.show();
        }

    @Override
    protected String doInBackground(String... params) {
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        if(MainCalendar.this.startingProgress != null) {
            MainCalendar.this.startingProgress.dismiss();
        }
    }
}

I also tried to call startActivity in onPostExecute, but it didn’t work. Therefore, I am waiting for your opinions and suggessions about this issue. Any help will be appreciated.

Thanks.

  • 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-14T23:16:36+00:00Added an answer on June 14, 2026 at 11:16 pm
    I also tried to call startActivity in onPostExecute,
    

    Pass the Activity context to startingThread AsyncTask and put your start activity code in onPostExecute() of AsyncTask.

    @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if(MainCalendar.this.startingProgress != null) {
                MainCalendar.this.startingProgress.dismiss();
                Intent toVisitRegister = new Intent(MainCalendar.this, VisitRegister.class);
                mContext.startActivity(toVisitRegister);
                mContext.finish();
            }
        }
    

    Here mContext is the Context of your current MainCalendar Activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android application and while switching between two activities I want to
I have two activities. In first I come to the second activity from first
I have two activities; Home is my first activity and Settings is my second
I have two activities. The first one executes the second one. Intent i =
Assume I have two activities. Activity A and Activity B, while Activity A is
This is my situation. I have two activities: ONE and TWO. In TWO activity
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have two activities, one is main and I have another activity called Test
I have an app with two activities. One of them list several values while
I have two activities in my Android project: Google Map Activity List Activity I'm

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.