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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:19:22+00:00 2026-05-26T19:19:22+00:00

im stuck in a situation where i am switching from activity 1 to activity

  • 0

im stuck in a situation where i am switching from activity 1 to activity 2.
i am using Thread.sleep(5000) to start another activity after 5 seconds
But the progress bar which i want to run for five seconds also sleeps with the first activity
Pleaze help me as to when i click next Button on first activity a progress bar shoud run for five sec
and then activity should be loaded
My Code is:

    public class Activity1 extends Activity  {          
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button next = (Button) findViewById(R.id.B);
    final ProgressBar  p=(ProgressBar) findViewById(R.id.pr);
    next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
              p.setVisibility(4);
            Thread t=new Thread();
            try{                    
                t.sleep(5000);              

        }
            catch(Exception e){}

            Intent myIntent = new Intent(view.getContext(), activity2.class);
            startActivityForResult(myIntent, 0);
        }

    });   

}}
  • 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-26T19:19:23+00:00Added an answer on May 26, 2026 at 7:19 pm

    Don’t use Thread.sleep() – it is the root to all evil. Instead, use a Handler and its postDelayed( Runnable, time )-method like below:

    public class Activity1 extends Activity  {          
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button next = (Button) findViewById(R.id.B);
      final ProgressBar  p=(ProgressBar) findViewById(R.id.pr);
      next.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
          p.setVisibility(4);
    
          final Handler handler = new Handler();
          handler.postDelayed(new Runnable() {
            @Override
            public void run() {
              Intent myIntent = new Intent(view.getContext(), activity2.class);
              startActivityForResult(myIntent, 0);
            }
          }, 5000);
        }
      });   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck in a situation from which I am finding no solution. Let
I'm using ASP.NET MVC 2 and stuck with the situation when needed to store
Answering to this question I stuck with this situation. Using reluctant match in my
I'm a bit stuck on what is probably a common situation, but can't find
I'm using jquery plugin tablesorter and I'm stuck with the following situation: my grid
Situation: I have a Service (also have tried using an Activity ) that sends
I got stuck in another situation: our users enter a text to be stored
I am stuck in weird situation. I want to upload photo from my iPad
I'm stuck with a LINQ group by situation trying to solve it without using
I stuck in a situation. I am using JS Helper. I used the following

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.