1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.util 18 19 import android.app.Activity 20 import android.os.Bundle 21 import android.os.PersistableBundle 22 import androidx.lifecycle.LifecycleOwner 23 import com.android.settingslib.core.lifecycle.Lifecycle 24 25 open class LifecycleActivity : Activity(), LifecycleOwner { 26 27 private val lifecycle = Lifecycle(this) 28 getLifecyclenull29 override fun getLifecycle() = lifecycle 30 31 override fun onCreate(savedInstanceState: Bundle?) { 32 lifecycle.onAttach(this) 33 lifecycle.onCreate(savedInstanceState) 34 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_CREATE) 35 super.onCreate(savedInstanceState) 36 } 37 onCreatenull38 override fun onCreate( 39 savedInstanceState: Bundle?, 40 persistentState: PersistableBundle? 41 ) { 42 lifecycle.onAttach(this) 43 lifecycle.onCreate(savedInstanceState) 44 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_CREATE) 45 super.onCreate(savedInstanceState, persistentState) 46 } 47 onStartnull48 override fun onStart() { 49 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_START) 50 super.onStart() 51 } 52 onResumenull53 override fun onResume() { 54 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_RESUME) 55 super.onResume() 56 } 57 onPausenull58 override fun onPause() { 59 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_PAUSE) 60 super.onPause() 61 } 62 onStopnull63 override fun onStop() { 64 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_STOP) 65 super.onStop() 66 } 67 onDestroynull68 override fun onDestroy() { 69 lifecycle.handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event.ON_DESTROY) 70 super.onDestroy() 71 } 72 }