Skip to content

Instantly share code, notes, and snippets.

@ziginsider
Created July 9, 2021 21:59
Show Gist options
  • Save ziginsider/2e4d2a95f3951f10bd3cec89a5dfc6ca to your computer and use it in GitHub Desktop.
Save ziginsider/2e4d2a95f3951f10bd3cec89a5dfc6ca to your computer and use it in GitHub Desktop.
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