惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
V2EX - 技术
V2EX - 技术
K
Kaspersky official blog
Know Your Adversary
Know Your Adversary
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
I
Intezer
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
博客园 - Franky
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research
The Hacker News
The Hacker News
T
Tenable Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
雷峰网
雷峰网
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Webroot Blog
Webroot Blog
L
LangChain Blog
C
Check Point Blog
N
News | PayPal Newsroom
L
LINUX DO - 热门话题
T
Tor Project blog
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
S
Security Affairs
Schneier on Security
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Stack Overflow Blog
Stack Overflow Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Security Latest
Security Latest
MyScale Blog
MyScale Blog
Cyberwarzone
Cyberwarzone
N
Netflix TechBlog - Medium
Scott Helme
Scott Helme
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
人人都是产品经理
人人都是产品经理
W
WeLiveSecurity

博客园 - 邢帅杰

.net core使用SharpZipLib压缩zip文件并设置密码 CSRedisCore用法 Android 常用数据目录(内部 / 外部、缓存、文件) 的 获取方法对照表 安卓把assets中的文件copy到app目录中 oracle执行sql语句前清除缓存 安装DockerDesktop并启用 oracle中decode用法 vue使用import.meta编译报错,import.meta.env报:类型“ImportMeta”上不存在属性“env”。必须配置module。 oracle游标使用详解 oracle存储过程中声明一个行变量,接收游标中的行数据。variable_name table_name%ROWTYPE oracle NVL和NVL2 C#获取文件md5码 oracle查询存储过程和函数中是否包含某个字符串 Android清除WebView缓存 C#获取当前日期是星期几 切换项目git地址,项目迁移到新git地址 C#线程同步、跨进程同步Mutex详解、C#只允许运行一个实例 Android Stack说明 安卓打开第三方app并传入参数 安卓如何唤醒深度睡眠的设备并执行任务 java两个日期相差秒数
安卓开发使用interface自定义回调函数
邢帅杰 · 2026-03-20 · via 博客园 - 邢帅杰

核心概念:回调的本质将一个方法(或接口实现)作为参数传递给另一个组件,由后者在特定时机主动调用该方法。
Java 实现方式:通过接口 + 接口实例实现(Java 无函数指针)。
注意:回调中不能直接更新 UI,需用 runOnUiThread() 或 Handler 切回主线程。

// 1. 定义回调接口
public interface DataCallback {
    void onSuccess(String data);
    void onError(Exception e);
}

// 2. 在异步任务中调用回调
public void fetchData(DataCallback callback) {
    new Thread(() -> {
        // 模拟网络请求
        String result = loadFromNetwork();
        if (callback != null) {
            callback.onSuccess(result); // 回调成功
        }
    }).start();
}

// 3. 使用时传入回调实现
fetchData(new DataCallback() {
    @Override
    public void onSuccess(String data) {
        runOnUiThread(() -> textView.setText(data)); // 更新 UI
    }

    @Override
    public void onError(Exception e) {
        Toast.makeText(this, "失败", Toast.LENGTH_SHORT).show();
    }
});