So, originally, I was pushing intents that needed to be sent across my application at regular intervals using a Service and a TimerTask. After reading the article at http://developer.android.com/resources/articles/timed-ui-updates.html it seemed that this would be the better approach. So, now, my Service creates a handler and sends it on its way. As in the article, my Handler postDelayed()'s itself, making it effectively run indefinitely (until the widget is removed, in which case I clear the handler, thus terminating execution).
My issue is, I know that Services can be eaten by Android for memory in the event that the user needs it. My Handler is a member variable of my Service. Say, for instance, Android eats my service, and then restarts it later on. That, as far as I understand, is a new instance of my Service, and so a new Handler will be instantiated and sent on its way. Aren't there now two handlers running? Or does the old handler get garbage collected (I'd think not because it has to be referenced somewhere else if it's still active)? Or does the first handler som开发者_开发问答ehow get shut down automatically? I don't want 8 of these things running at the same time.
Handler is part of the Thread and Thread is part of Process. When OS kills a Serivce it purges the whole process.
精彩评论