Created
September 17, 2017 22:29
-
-
Save nisrulz/cc9e23e3c9411a0f147cdc6e04cfa830 to your computer and use it in GitHub Desktop.
Making your Android Library, Lifecycle-Aware blog post code snippet: AwesomeLibMain class after lifecycle components have been integrated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.arch.lifecycle.Lifecycle; | |
import android.arch.lifecycle.LifecycleObserver; | |
import android.arch.lifecycle.OnLifecycleEvent; | |
public class AwesomeLibMain implements LifecycleObserver { | |
static final AwesomeLibMain ourInstance = new AwesomeLibMain(); | |
public static AwesomeLibMain getInstance() { | |
return ourInstance; | |
} | |
private AwesomeLibMain() { | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE) | |
public void init() { | |
System.out.println( | |
"Called From AwesomeLibMain Class, called onCreate() of Activity >>>>>> init()"); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
public void LibOnStart() { | |
System.out.println( | |
"Called From AwesomeLibMain Class, called onStart() of Activity >>>>>> LibOnStart()"); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
public void LibOnStop() { | |
System.out.println( | |
"Called From AwesomeLibMain Class, called onStop() of Activity >>>>>> LibOnStop()"); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME) | |
public void LibOnResume() { | |
System.out.println( | |
"Called From AwesomeLibMain Class, called onResume() of Activity >>>>>> LibOnResume()"); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) | |
public void LibOnPause() { | |
System.out.println( | |
"Called From AwesomeLibMain Class, called onPause() of Activity >>>>>> LibOnPause()"); | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) | |
public void cleanup() { | |
System.out.println( | |
"Called From AwesomeLibMain Class, called onDestroy() of Activity >>>>>> cleanup()"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment