【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");
        }
    };
相关推荐
zyseo817 分钟前
谷歌SEO 站内搜索优化实战:把站内搜索词变成关键词金矿
java·服务器·数据库
bug菌25 分钟前
🤔同事突然问我:Spring的注解 @Component 和 @Service 有何不同?
java·spring boot·后端
佳児素花痴╮29 分钟前
线程知识点
java·开发语言·jvm
leobertlan30 分钟前
痛苦系列 | DSP-02 频域切片:DTFT与DFT的探索
android·后端
用户117953654781 小时前
TRAE vs Claude Code 性能对比:从代码生成、多文件重构到底层吞吐,谁更适合你的日常开发?
javascript
fundoit1 小时前
为什么需要 Access Token 和 ID Token 两个令牌
java·spring·架构·github·oauth2
leobertlan1 小时前
痛苦系列 | DSP-01 从连续到离散:DSP基础与采样
android·后端
鱼宵2 小时前
Spring AI 流式输出:Flux + SSE 打字机,回答不再干等三秒
java·人工智能·spring·sse·springai·流式输出
shaibdoio2 小时前
AI主动获客的意图识别工程实现:从规则匹配到模型微调
java·开发语言·人工智能·长沙瞬维ai
kill5222 小时前
useRef
前端·javascript·react.js