【Android】乱七八糟的小结

1.死亡回调

java 复制代码
private final ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            logD("launcher aidl connected");
            iLauncher = ILauncher.Stub.asInterface(service);
            try {
                // 为Binder 对象设置死亡回调,当绑定的服务进程死亡时,会触发这个回调
                iLauncher.asBinder().linkToDeath(new IBinder.DeathRecipient() {
               		// 当绑定的服务进程死亡时,系统会调用这个方法
                    @Override
                    public void binderDied() {
                        Log.d(TAG,"[binderDied] retry bindService!");
                        // 然后将 iLauncher 置为 null,以释放对旧服务代理对象的引用
                        iLauncher = null;
                        // 最后调用 bindService() 方法,尝试重新绑定服务
                        bindService();
                    }
                },0);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            logD("launcher aidl disconnected");
        }
    };
相关推荐
ps酷教程4 小时前
Jackson 解决没有无参构造函数的反序列化问题
java
NiceCloud喜云4 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
GISer_Jing5 小时前
Three.js着色器编译机制深度解析
javascript·webgl·着色器
丷丩5 小时前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
油炸自行车5 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
_日拱一卒5 小时前
LeetCode:994腐烂的橘子
java·数据结构·算法·leetcode·深度优先
隔窗听雨眠5 小时前
Nginx网关响应慢排查手记
java·服务器·nginx
智慧物业老杨6 小时前
智慧物业合同周期管理系统:从风险预警到智能交接的全流程数智化落地方案
java·人工智能·python
源码宝6 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展
java·后端·源码·springboot·mes系统·源码二开·mes源码
JAVA社区6 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展