Passing a thread object to service

868 views.

In my activity I start a thread which works a long time. In order to stop the thread at application termination (when the user removes it from the recent app list), I want to call thread.interrupt() in a service inside void onTaskRemoved(Intent rootIntent). But I have no access to my thread object in my activity. So my question is: How can I pass the thread to my service?

Add Comment
1 Answer(s)
482 views.

You can’t. Threads don’t implement serializable or Parcelable. And passing a thread between a Service and Activity sounds like a horrible code smell. Just create it in the Service.

Also- remove it from the task bar? What task bar? There is no task bar in android, unless you have some odd UI running.

Answered on July 5, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.