Android BroadcastReceiver Thread/Timer as static instance variable
开发者_运维百科The android developer site states that a BroadcastReceiver process is eligible to be removed after the onReceive() method returns and that you should not start threads/timers within the BroadcastReceiver. But how does this relate to static instance variables of the Thread/Timer class? I assume that these static instance variables still exists because they are bound to the loaded class? Or am I wrong (e.g. because the process is started within a new dalvik JVM) and should I never use threads/timers within BroadcastReceivers?
Or am I wrong (e.g. because the process is started within a new dalvik JVM) and should I never use threads/timers within BroadcastReceivers?
If the BroadcastReceiver
is registered in the manifest, do not fork threads, start timers, register listeners, or otherwise do anything tied to that receiver that would need to live beyond the receiver. If there is nothing else in your app running, your process is eligible for termination at any time, taking your stuff with you.
If the BroadcastReceiver
is registered via registerReceiver()
from some other component, that other component can fork threads, start timers, register listeners, or whatever else, subject to the normal rules of that component.
精彩评论