fix(settings): 重构SN上报并清理失效启动页
- SettingsViewModel改用SnRepository进行设备注册 - 移除RxLifecycle手动绑定基类,改用AndroidX Lifecycle - 新增系统、硬件、网络、安全、定位等SN信息上报接口 - 修复ContactInfo equals逻辑错误 - 应用列表变化后自动清理失效启动页
This commit is contained in:
@@ -1,43 +1,18 @@
|
||||
package com.ttstd.dialer.base;
|
||||
|
||||
import android.content.Intent;
|
||||
import androidx.lifecycle.LifecycleService;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LifecycleRegistry;
|
||||
/**
|
||||
* Service 基类(基于 AndroidX {@link LifecycleService})。
|
||||
* <p>
|
||||
* 通过继承 {@link LifecycleService} 自动获得:
|
||||
* - {@link androidx.lifecycle.LifecycleOwner} 能力
|
||||
* - 生命周期事件自动派发:onCreate → ON_CREATE,onStartCommand → ON_START / ON_RESUME,onDestroy → ON_DESTROY
|
||||
* (其中 ON_START / ON_RESUME 满足 Service 中 LiveData 的触发条件,无需再手动修补)
|
||||
* - 不再需要手动维护 {@link androidx.lifecycle.LifecycleRegistry} 或覆写生命周期方法派发事件
|
||||
* <p>
|
||||
* 子类如需在生命周期回调中做处理,可直接覆写 onStartCommand / onDestroy 并调用 super。
|
||||
*/
|
||||
public abstract class BaseService extends LifecycleService {
|
||||
|
||||
import com.ttstd.dialer.base.rx.BaseRxService;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BaseService extends BaseRxService implements LifecycleOwner {
|
||||
|
||||
private final LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Lifecycle getLifecycle() {
|
||||
return lifecycleRegistry;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
||||
//修补在Service中LiveData不能触发
|
||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user