gpt4 book ai didi

java - 如何在 Activity 中显示通过服务获取的数据?

转载 作者:太空宇宙 更新时间:2023-11-04 11:35:45 25 4
gpt4 key购买 nike

我有一个从网络下载一些数据的服务,但是当我尝试将其传递给 Activity 以将其显示给用户时,我收到以下错误:

E/JavaBinder:!!! BINDER 交易失败!!!

// This gets populated in the server based on information from a server.
byte[] downloadedData;
// Instantiated downloadedData from server connection, code removed for brevity.

// Try to start activity with downloaded data.
Intent i = new Intent(this, MainActivity.class);
i.putExtra("DATA", downloadedData);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

最佳答案

尝试

1.在您的 Activity 中注册自定义广播接收器

context.registerReceiver (myBroadcastReceiver, new IntentFilter ("CUSTOM_ACTION"));
private final BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver () {

@Override
public void onReceive (Context context, Intent intent) {

//Do something
}
};

2.从您的服务发送广播

Intent intent = new Intent ("CUSTOM_ACTION");
intent.putExtra("DATA", downloadedData);
context.sendBroadcast (intent)

关于java - 如何在 Activity 中显示通过服务获取的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43310630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com