How to Pause an Activity?


Last Updated:

  1. Beanstalk

    Beanstalk Member This Topic's Starter

    Joined:
    Jun 24, 2010
    Messages:
    9
    Likes Received:
    0
    Is there any way to pause an activity for a brief period of time? What I want to do is implement a "Loading..." splash screen which updates the "Loading" bar at regular intervals.

    What I've seen so far is wait(millis) and Thread.sleep(millis).
    The former gives terrible runtime errors and the latter puts even the monitor to sleep for that duration, hence defeating the purpose of using the sleep() altogether.

    I basically want the app to freeze in it's current state for a few seconds.

    Thanks in advance :eek:
     

    Advertisement
  2. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
  3. blundell

    blundell Well-Known Member

    Joined:
    Apr 23, 2010
    Messages:
    125
    Likes Received:
    17
    I don't know why you want to pause your app, but this will do it:
    Code (Text):
    1.  
    2. final ProgressDialog pausingDialog = ProgressDialog.show(YourClassName.this, "", "Loading..", true);
    3.         new Thread() {
    4.             public void run() {
    5.                 Thread.sleep(5000); // The length to 'pause' for               
    6.                 pausingDialog.dismiss();
    7.             }
    8.         }.start();     
    9.  
    Thank my post if this answers your Q :)

    Technically it won't pause your app but It'll look like it to your user
     
  4. cp1

    cp1 Well-Known Member

    Joined:
    Apr 30, 2010
    Messages:
    375
    Likes Received:
    35

Share This Page

Loading...