1. Check out our companion app, Forums for Android! Download from Google Play

How to Pause an Activity?

Discussion in 'Application Development' started by Beanstalk, Aug 9, 2010.

  1. Beanstalk

    Beanstalk Member
    Thread Starter
    5

    Jun 24, 2010
    9
    0
    5
    Student
    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
    38

    Apr 20, 2010
    142
    23
    38
    Student.. also software developer
    Netherlands
  3. blundell

    blundell Well-Known Member
    38

    Apr 23, 2010
    125
    17
    38
    Software Engineer
    UK
    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
     

Share This Page

Loading...