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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:40:35+00:00 2026-05-21T19:40:35+00:00

Well, please don’t ask me why, but I need to start a synchronous and

  • 0

Well, please don’t ask me why, but I need to start a synchronous and blocking activity so that the program flow won’t continue until it’s finished. I know how to do a synchronous Dialog, but how can I do a synchronous activity?

Following are two approaches I tried but failed:

// In the 1st activity, start the 2nd activity in the usual way
startActivity(intent);
Looper.loop();        // but pause the program here
// Program continuse running afer Looper.loop() returns
....

// Then, in the second activity's onBackPressed method:
public void onBackPressed() {
    // I was hoping the following quit() will terminate the loop() call in
    // the first activity. But it caused an exception "Main thread not allowed
    // to quit." Understandable.
    new Hanlder().getLooper().quit();
}

I also tried to use another thread to achieve this:

// In the first activity, start a thread
SecondThread m2ndThread = new SecondThread(this);
Thread th = new Thread(m2ndThread, "Second Thread");
th.run();
synchronized(m2ndThread) {
    m2ndThread.wait();
}

class SecondThread implements Runnable {

    Activity m1stActivity;

    SecondThread(Activity a) {
        m1stActivity = a;
    }

    public void run() {
        Looper.prepare();
        Handler h = new Handler() {
            public void handleMessage() {
                Intent intent = new Intent(m1stActivity, SecondActivity.class);
                m1stActivity.startActivity(intent); // !!!!!!!!!!!!!!
            }
        }
        h.sendEmptyMessage(10); // let it run
        Looper.quit();
    }
}

However, this approach doesn’t work because when I’m using the 1st activity to start the 2nd activity, the main thread is already in wait state and doing nothing. So the 2nd activity didn’t even get created. (This is ironical: You have to use an activity to start an activity, but how can you do that when it’s already in wait state?)

  • 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-05-21T19:40:35+00:00Added an answer on May 21, 2026 at 7:40 pm

    You can’t.

    That is all there is to it. You just can’t do this. Activities execute on the main thread, always. Your main thread must be actively running its event loop. It is ALWAYS broken to block the main thread’s event loop. Always.

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

Sidebar

Related Questions

I have a bunch of php arrays that look like this (please don't ask
well I need a method to convert word files to swf. please don't suggest
I don't mean for this to be inflammatory, so please don't take it that
I would like to assert that a particular method was called, but I don't
Well, I'm completely new to JavaScript. Can you please tell me what type of
Please i have an issue with my form background image display. It works well
Well, not random, because its the same every time, but #include<iostream> using namespace std;
Well, for integers I would use NSNumber . But YES and NO aren't objects,
Well, I have a class Customer (no base class). I need to cast from
I need to update (well, rewrite really) a SMALL VB6 application which uses ADO

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.