1. Download our Official Android App: Forums for Android!

Apps How to Pause an Activity?

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

  1. Beanstalk

    Beanstalk Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    9
    Joined:
    Jun 24, 2010

    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
    Rank:
    None
    Points:
    38
    Posts:
    142
    Joined:
    Apr 20, 2010

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

    blundell Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    124
    Joined:
    Apr 23, 2010

    Apr 23, 2010
    124
    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
     
  4. cp1

    cp1 Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    375
    Joined:
    Apr 30, 2010

    Apr 30, 2010
    375
    35
    53

Share This Page

Loading...