Last active
November 15, 2018 16:20
-
-
Save dinorahtovar/963837024ff6e7583ff5afe1602a1544 to your computer and use it in GitHub Desktop.
LifecycleObserver to check OnPause and OnResume
This file contains hidden or 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
/** | |
* Created by Dinorah Tovar on 2/22/18. | |
* Application Owner using lifecycleObserver to know the application of | |
* the application. | |
*/ | |
class ApplicationOwner : LifecycleObserver { | |
/** | |
* Companion Object | |
*/ | |
companion object { | |
var observer: Boolean = false | |
var observerDestroy: Boolean = false | |
} | |
/** | |
* Application is starting again | |
*/ | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onStartApplication() { | |
if (observer) { | |
val intent = Intent(context, SplashActivity::class.java) | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
context.applicationContext.startActivity(intent) | |
} | |
} | |
/** | |
* Application was stopped from user perspective | |
*/ | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun onStopApplication() { | |
if (observerDestroy) { | |
observer = false | |
observerDestroy = false | |
} else { | |
observer = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment