Reputation: 4727
//Creates a new Timer which may be specified to be run as a daemon thread.
Timer(boolean isDaemon)
//Creates a new non-daemon Timer.
Timer()
When does a timer should be started as Daemon inside an android app ?
The documentation says nothing about it .
http://developer.android.com/reference/java/util/Timer.html
Upvotes: 19
Views: 12529
Reputation: 68187
If your application is running a user-thread (i.e. non-daemon thread) then the JVM will wait till the return of its run()
method (or the thread has completed its execution) before it terminates the application. However, if your thread is set as daemon, then it instructs the JVM not to wait for the completion of its execution in case the JVM needs to close down the application (i.e. when no other user threads are running). Other than this, both types of threads are treated equally in all other aspects.
In your case, you should not set your Timer
as daemon thread, until and unless you don't want its execution to hold the termination of application.
For more information, read this and this.
Upvotes: 14