【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");
        }
    };
相关推荐
考虑考虑44 分钟前
Java实现hmacsha256加密算法
java·后端·java ee
captain3761 小时前
▲网络原理(2)-TCP
java·服务器·网络·tcp/ip·java-ee
MetaLite1 小时前
SpringBoot接口分层规范-外网网关内部服务与参数边界
java·数据库·spring boot
Co_Hui1 小时前
Java 线程状态
java
土司大王2 小时前
LeetCode hot100——35.搜索插入位置:Java 二分模板、左闭右开区间与插入点分析
java·算法·leetcode
土司大王2 小时前
LeetCode hot100——34.在排序数组中查找元素的第一个和最后一个位置:Java 二分模板、边界分析
java·算法·leetcode
金金计较.2 小时前
Go语言-3
java·开发语言·golang
Wang's Blog3 小时前
Java框架快速入门: Spring Security+OAuth2之元注解简化权限表达式
java·数据库·spring
xifangge20254 小时前
AGENTS.md 怎么写?涵盖 Java、Python、Vue、Go 的 8 套开箱即用模板
java·vue.js·python
Wang's Blog4 小时前
Java框架快速入门: Spring Security+OAuth2之云服务集成与多因子认证设计
java·开发语言·spring