• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to Pause an Activity?

Beanstalk

Lurker
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 :o
 
You should use an AsyncTask for this. It doesn't make your app hang so you can put a while loop in it. If you want to update a loading bar you have to override the onProgressUpdate() method and update it from there.
AsyncTask.html
http://developer.android.com/reference/android/os/AsyncTask.html

-id
 
I don't know why you want to pause your app, but this will do it:
Code:
final ProgressDialog pausingDialog = ProgressDialog.show(YourClassName.this, "", "Loading..", true);
		new Thread() {
			public void run() {
				Thread.sleep(5000); // The length to 'pause' for				
				pausingDialog.dismiss();
			}
		}.start();

Thank my post if this answers your Q :-)

Technically it won't pause your app but It'll look like it to your user
 
Back
Top Bottom