Created
July 5, 2018 13:30
-
-
Save gbzarelli/94d8f9ca5a9278cd38f233d8580e1433 to your computer and use it in GitHub Desktop.
Como detectar se a aplicação está minimizada ou não (How to detect Android application in background or foreground events)
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
/** | |
Doc: https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner | |
belongs to Maven artifact "android.arch.lifecycle:extensions:1.1.1" (include in your dependences) | |
*/ | |
class MyApplication : Application(), LifecycleObserver { | |
override fun onCreate() { | |
super.onCreate() | |
ProcessLifecycleOwner.get().lifecycle.addObserver(this) | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun onAppBackgrounded() { | |
Log.d(LOG, "App in background") | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onAppForegrounded() { | |
Log.d(LOG, "App in foreground") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment