I know we can use
But I have requirement that a class keeps running and never gets removed but garbage collector.
If you ask about "class" in general, you can use a
static variable. It will never be garbage collected unless you assign
null to it because a class object will hold a strong reference to it.
So when an activity or service fires an event the central event class catches that event and does whatever needed.
BroadcastReceiver component for this. It was designed exactly for this purpose.
I don't see how your first question is related to the second one though.. I suppose you want your receiver to always handle events. So in this case just register it in
AndroidManifest.xml so that it will run every time event occurs.