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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:09:21+00:00 2026-05-23T11:09:21+00:00

this is my scenario: I’ve got a login screen that opens another activity. In

  • 0

this is my scenario: I’ve got a login screen that opens another activity. In the Activity I simply have:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
}

The layout is kind of heavy, cause it is made of some fragments, and takes about 1.5 seconds to load.
Now, how can I display a ProgressDialog while setContentView finishes inflating the layout? I’ve tried with AsyncTask by putting the setContentView in the doInBackground, but of course that cannot be done, as the UI can be updated from the UI thread only.
So I need to call setContentView in the UI thread, but where do I have to show/dismiss the ProgressDialog?

I appreciate your help.

Fra.

EDIT: I followed @JohnBoker’s previous suggestion, this is the code I have now:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_empty_layout);
    new ContentSetterTask().execute("");
}

private class ContentSetterTask extends AsyncTask<String, Void, Void> {

    public ProgressDialog prgDlg;

    @Override
    protected void onPreExecute() {
        android.os.Debug.waitForDebugger();
        prgDlg = ProgressDialog.show(MultiPaneActivity.this, "", "Loading...", true);

    }

@Override
protected Void doInBackground(String... args) {
    android.os.Debug.waitForDebugger();
    ViewGroup rootView = (ViewGroup)findViewById(R.id.emptyLayout);
    LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View inflated = inflater.inflate(R.layout.activity_details, rootView);
    return null;
}

@Override
protected void onPostExecute(Void arg) {
    android.os.Debug.waitForDebugger();
    if (prgDlg.isShowing())
        prgDlg.dismiss();
    }
  }
}

The row

View inflated = inflater.inflate(R.layout.activity_details, rootView);

gives me the error:

06-27 16:47:24.010:   
ERROR/AndroidRuntime(8830): Caused by:android.view.ViewRoot$CalledFromWrongThreadException: 
Only the original thread that created a view hierarchy can touch its views.
  • 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-23T11:09:21+00:00Added an answer on May 23, 2026 at 11:09 am

    I decided to make a full answer here for future readers.

    After several hours spent on the issue, I realized that the issue is I’m trying to do two things:

    1. inflating a layout, which is an
      operation that NEEDS to be made on
      the UI thread by design.
    2. showing a Dialog (ProgressDialog,
      actually, but this does not change
      the outcome), that can be done from
      the UI thread only, since Services
      can’t show any Dialog.

    So, as both calls are made from the UI thread (onCreate or AsyncTask makes no difference, it’s still the UI thread), the first blocks the second one from showing up appropriately.
    Bottom line is: this problem can’t be solved in Android right now. Let’s hope we can get some better APIs for interacting with the UI, because the ones we’ve got kind of suck.

    I’m going to solve this problem by changing the layout and making it lighter (if possible!).
    Thanks everyone!

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

Sidebar

Related Questions

Consider this scenario. I have my own website, that I use as my identifier,
Consider this scenario. I have some business logic that now and then will be
I have this scenario: One custom class (Customer) with some properties, like this: public
I got stuck with this scenario. Let me explain as follows. I have a
I have this scenario: class A { public virtual int Id { get; set;
Consider this scenario. We have an internal Rails 2 app that connects to a
Imagine this scenario: you have a WCF web service that gets hit up to
Using Pymongo for this scenario. I have User that has email, first_name, last_name. I
Have this scenario: public class Base { public string Name; } public Class ClassA
I have this scenario: I have a mysql database, with a table that contain

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.