1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to Pause an Activity?

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

  1. Beanstalk

    Beanstalk Lurker
    Thread Starter

    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:
     


  2. id0001

    id0001 Well-Known Member

  3. blundell

    blundell Well-Known Member

    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
     
Loading...
Similar Threads - Pause Activity
  1. 8angr0ves
    Replies:
    3
    Views:
    296
  2. GPerson
    Replies:
    4
    Views:
    255
  3. Niall Harrison
    Replies:
    3
    Views:
    280
  4. MoodyBlues
    Replies:
    3
    Views:
    500
  5. CDSoftwares
    Replies:
    3
    Views:
    796
  6. CybeRoky
    Replies:
    4
    Views:
    376
  7. Dima_G
    Replies:
    2
    Views:
    993
  8. guycarnegie
    Replies:
    2
    Views:
    606
  9. Drifterr
    Replies:
    9
    Views:
    5,431
  10. Bhimesh Sharma
    Replies:
    1
    Views:
    443

Share This Page

Loading...