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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:25:01+00:00 2026-06-04T20:25:01+00:00

I have one button in the main.xml which will link to another xml which

  • 0

I have one button in the main.xml which will link to another xml which include information from server. I include progress bar to avoid the blank screen while the system is loading the information. i already done the code as below but it’s still not the things i wanted. the code below will “WAIT” for 1000 ms then only will execute the next code. how can i modify it so that the loading “WAIT TIME” will depends on the internet speed, if internet connection is slow, then the progress-bar-screen will show longer.

package com.android.myApps;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

public class MainScr extends Activity {

    private final int WAIT_TIME = 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {       
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.MainScr);       
    }   

    public void onClickCategory(View view)
    {
        findViewById(R.id.mainSpinner1).setVisibility(View.VISIBLE);
        new Handler().postDelayed(new Runnable(){
            @Override
                public void run() {                          
                      Intent mainIntent = new Intent(MainScr.this, Category.class); 
                      MainScr.this.startActivity(mainIntent); 
                      MainScr.this.finish(); 
                      } 
            }, WAIT_TIME);
    }
}
  • 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-04T20:25:03+00:00Added an answer on June 4, 2026 at 8:25 pm

    The mistake you are doing here is you are dumping specific time into your code
    You never know how much it will take to get response.
    You should follow following approach

    Step 1 Show progress dialog on screen

    Step 2 Let download take its own time.But it should be done in new thread

    Step 3 Once download is complete it will raise message that task is done,now remove that
    progress dialog and proceed.

    I am pasting sample code here.Hope it will help you.

    package com.android.myApps;
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    
    public class MainScr extends Activity
    {
        private Handler handler;
        private ProgressDialog progress;
        private Context context;
    
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            context = AncActivity.this;
            progress = new ProgressDialog(this);
            progress.setTitle("Please Wait!!");
            progress.setMessage("Wait!!");
            progress.setCancelable(false);
            progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    
            handler = new Handler()
            {
    
                @Override
                public void handleMessage(Message msg)
                {
                    progress.dismiss();
                    Intent mainIntent = new Intent(context, Category.class);
                    startActivity(mainIntent);
                    super.handleMessage(msg);
                }
    
            };
            progress.show();
            new Thread()
            {
                public void run()
                {
                    // Write Your Downloading logic here
                    // at the end write this.
                    handler.sendEmptyMessage(0);
                }
    
            }.start();
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one spinner in which few values are there from strings.xml and I
I have a one button on my main storyboard. I'm pretty sure it's linked
My application is viewbased application in which I have one button. On click of
I have crated a class which extends the ListFragment . I have one button
My main.xml layout simply contains a button and a LinearLayout content_area , which shows
I have two layouts(xml files) and I want to flip from one page to
fI have created two layout files. First one is main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have one button for this slider. The slider has three sections. Frame 24
I have one form with several text fields and one button. When i enter
In my code I have one textbox and one button. Whatever place you type

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.