Application pin code逻辑实现
2020-04-17 本文已影响0人
花艺荣
public class AppCoreBase extends Application implements Application.ActivityLifecycleCallback
public void onCreate()
{
mScreenObserver = new ScreenObserver(getApplicationContext());
mScreenObserver.requestScreenStateUpdate(new ScreenObserver.ScreenStateListener() {
@Override
public void onScreenOn() {
doSomethingOnScreenOn();
}
@Override
public void onScreenOff() {
doSomethingOnScreenOff();
}
});
registerActivityLifecycleCallbacks(this);
}
@Override
public void onTerminate() {
super.onTerminate();
mScreenObserver.stopScreenStateUpdate();
unregisterActivityLifecycleCallbacks(this);
}
@Override
public void onActivityStarted(@NonNull Activity activity) {
}
@Override
public void onActivityStopped(@NonNull Activity activity) {
}
@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
}
@Override
public void onActivityDestroyed(@NonNull Activity activity) {
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
}
@Override
public void onActivityResumed(@NonNull Activity activity) {
// do something here
}
@Override
public void onActivityPaused(@NonNull Activity activity) {
// do something here
}