0

Is there a way in which I can have an android activity to sleep instead of the entire application going to sleep. I want the original activity to wait for 10 seconds and implement the code in it while I am using the next activity. However, using Thread.sleep(), the entire application goes to sleep. Is there any other way to do this apart from Thread.sleep()?

try { Thread.sleep(10000); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }

Suraj
  • 123
  • 1
  • 5
  • this might help http://stackoverflow.com/questions/11548864/how-to-make-an-android-program-wait – LotusUNSW Nov 09 '13 at 05:59
  • Do you want to sleep because you want to do an operation in the background? Or does the user need to perform a specific task in a certain time? – FabianCook Nov 09 '13 at 06:38
  • I want it to sleep to perform an operation in the background but launch again at the end of the operation. – Suraj Nov 09 '13 at 06:41

1 Answers1

0

Simply launch the other activity. Android will pause the first activity for you. Android will invoke that activity's "onPause" method when this happens.

I suggest you read up on the Android Activity Lifecycle: http://developer.android.com/training/basics/activity-lifecycle/index.html.

Or if you want the activity launch to happen at some point in the future, try using a timer task: http://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html

EJK
  • 12,332
  • 3
  • 38
  • 55
  • I am sorry but I am not able to frame a proper question around what I want. I want it to pause for a specific time period after which it should launch while I am using another activity. – Suraj Nov 09 '13 at 06:16
  • What are your expectations for what should happen during this "pause". Can the user still interact with the current activity? – EJK Nov 09 '13 at 06:23
  • Yes, she should be able to interact with the current activity – Suraj Nov 09 '13 at 06:27
  • See the above answer. I added a suggestion about using a Java TimerTask. This sounds like what you want. – EJK Nov 09 '13 at 06:34