Is there a way in android to bind to an activity's lifecycle events? I'm making a library and I'd like to hook into onCreate etc. The iOS version of the lib does it like this:
- (void)observe
{
[self bindAppEvent:UIApplicationDidBecomeActiveNotification toMethod:@selector(applicationDidBecomeActiveHandler:)];
[self bindAppEvent:UIApplicationWillResignActiveNotification toMethod:@selector(applicationWillResignActiveHandler:)];
[self bindAppEvent:UIApplicationWillTerminateNotification toMethod:@selector(applicationWillTerminateHandler:)];
}
#pragma mark Private Methods
- (void)bindAppEvent:(NSString *)appEvent toMethod:(SEL)aSelector
{
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:aSelector
name:appEvent
object:app];
}
thanks!
You can use Application.registerActivityLifecycleCallbacks to register your own callbacks to activity life-cycle events.
Requirements: