有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在活动中显示通过服务获得的数据?

我有一个从网上下载一些数据的服务,但当我试图将其传递给活动并向用户显示时,我收到以下错误:

E/JavaBinder:!!!活页夹事务失败

// 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) 个答案

  1. # 1 楼答案

    试试看

    1在活动中注册自定义广播接收器

    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)