Created
July 9, 2021 21:59
-
-
Save ziginsider/2e4d2a95f3951f10bd3cec89a5dfc6ca to your computer and use it in GitHub Desktop.
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
class MainActivity : AppCompatActivity(), LifecycleObserver { | |
private lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
ProcessLifecycleOwner.get().lifecycle.addObserver(this) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
/* ... */ | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun onAppBackgrounded() { | |
// Background | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onAppForegrounded() { | |
// Foreground | |
} | |
/* ... */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment