tags:

views:

38

answers:

2

Hello everyone,

I want to know that when the Thread is running then if I press the home key of the emulator/device, then what will happen? Will thread gone be close or pause or any other?

waiting for your quick reply.

BR, gsmaker

A: 

UI thread (Activity) will be paused and then stopped.

If you mean Thread object runned from Activity then it will be continue running. It may cause various problems, so it will be better manually interrupt such threads.

Sergey Glotov
A: 

If you want it running only if the Activity is visible, you'll have to call interrupt() on the Thread in onPause() and start the thread again in onResume(). Read something about interrupt (docs or Google), basically it throws InterruptedException in your thread but only if it's in waiting/sleeping state. What is your thread doing?

fhucho
Thanks for your reply. Actually my thread deletes some files. But when the thread runs and deleting some files and at this time if I press home key the app goes foreground but the thread can't delete some file.
gsmaker