启动活动时失败的粘合剂交易

时间:2013-12-12 20:59:39

标签: android android-asynctask garbage-collection android-binder

我认为我的问题可能与这个堆栈帖子(Android remote method data limit)有关 - 只返回的数据大小为661KB,文章说绑定器可以支持1MB。

以下是这种情况:我有一个异步任务,它接受一个参数并调用一个Web服务,该服务返回一个管道分隔的字符串和整数值的数组列表。然后我将这些值并插入到JAVA arraylist中。在较小的数据集中,这很好。在较大的数据集(即这个661KB数据集)中,我得到以下错误。

logcat的:

12-12 15:33:46.118: D/ProgressBar(14998): setProgress = 0
12-12 15:33:46.118: D/ProgressBar(14998): setProgress = 0, fromUser = false
12-12 15:33:46.118: D/ProgressBar(14998): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 10000
12-12 15:33:46.168: I/Async_GetAllTechSched(14998): create soap object
12-12 15:33:46.168: I/Async_GetAllTechSched(14998): create envelope
12-12 15:33:46.168: I/Async_GetAllTechSched(14998): create transport
12-12 15:33:46.208: D/ProgressBar(14998): updateDrawableBounds: left = 0
12-12 15:33:46.208: D/ProgressBar(14998): updateDrawableBounds: top = 0
12-12 15:33:46.208: D/ProgressBar(14998): updateDrawableBounds: right = 144
12-12 15:33:46.208: D/ProgressBar(14998): updateDrawableBounds: bottom = 144
12-12 15:33:51.613: D/dalvikvm(14998): GC_FOR_ALLOC freed 6262K, 37% free 18436K/29244K, paused 24ms, total 24ms
12-12 15:33:51.944: D/dalvikvm(14998): GC_FOR_ALLOC freed 594K, 36% free 18880K/29244K, paused 29ms, total 30ms
12-12 15:33:51.974: D/dalvikvm(14998): GC_FOR_ALLOC freed <1K, 34% free 19556K/29244K, paused 29ms, total 29ms
12-12 15:33:52.084: D/dalvikvm(14998): GC_FOR_ALLOC freed 2307K, 27% free 21387K/29244K, paused 20ms, total 20ms
12-12 15:33:52.204: D/dalvikvm(14998): GC_FOR_ALLOC freed 1597K, 25% free 22117K/29244K, paused 22ms, total 22ms
12-12 15:33:52.244: I/Async_GetAllTechSched(14998): pre SOAP response
12-12 15:33:52.244: I/Async_GetAllTechSched(14998): post SOAP response
12-12 15:33:52.244: I/Async_GetAllTechSched(14998): PRE - add response to array
12-12 15:33:52.244: I/Async_GetAllTechSched(14998): POST - add response to array
12-12 15:33:52.244: I/Async_GetAllTechSched(14998): pre-intent setting
12-12 15:33:52.244: I/Async_GetAllTechSched(14998): post-intent setting
12-12 15:33:52.254: I/Async_GetAllTechSched(14998): dismiss progress
12-12 15:33:52.264: E/JavaBinder(14998): !!! FAILED BINDER TRANSACTION !!!
12-12 15:33:52.274: E/ViewRootImpl(14998): sendUserActionEvent() mView == null

以下是正在执行的代码:

Log.i("Async_GetAllTechSched", "create soap object");
SoapObject request = new SoapObject(svc_NAMESPACE, svc_METHOD_NAME);

Log.i("Async_GetAllTechSched", "create envelope");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);

envelope.dotNet = true;
envelope.setOutputSoapObject(request);

Log.i("Async_GetAllTechSched", "create transport");
HttpTransportSE androidHttpTransport = new HttpTransportSE(svc_URL);
androidHttpTransport.debug = true;

try {

    androidHttpTransport.call(svc_SOAP_ACTION, envelope);

    Log.i("Async_GetAllTechSched", "pre SOAP response");

    // use SoapObject instead of SoapPrimitave
    SoapObject response = (SoapObject) envelope.getResponse();

    Log.i("Async_GetAllTechSched", "post SOAP response");

    // get the count of the objects returned
    int cnt = response.getPropertyCount();

    Log.i("Async_GetAllTechSched", "PRE - add response to array");

    // loop through returned object and pull out the strings
    for (int i = 0; i < cnt; i++) {

        // there should always be at least one return value
        sResponse.add(response.getProperty(i).toString());
    }

    Log.i("Async_GetAllTechSched", "POST - add response to array");

} catch (Exception e) {

    e.printStackTrace();

    Log.e("!!ERROR!!", e.getMessage());

    }

    // Log.i("return in async", "*********");
    return sResponse;
}

@Override
protected void onPostExecute(ArrayList<String> result) {



ArrayList<String> arrAllTechSchedule = new ArrayList<String>();

    // get the count prior to the for loop
    int iCnt = result.size();

    //add the result of the web service call to the main scheduling page
    for (int i = 0; i < iCnt; i++) {
        //Log.i("i = ", Integer.toString(i));

        //add the data to a ArrayList so we can add that to the adapter 
        arrAllTechSchedule.add(result.get(i).toString());   
    }       

    // lets launch the main schedule windows

    Log.i("Async_GetAllTechSched", "pre-intent setting");

    Intent intent = new Intent(_Context, ScheduleSelectTech.class);
    intent.putStringArrayListExtra("arrAllTechSchedule", arrAllTechSchedule);
    intent.putExtra("mode", "READ-ONLY");

    Log.i("Async_GetAllTechSched", "post-intent setting");

    // terminate the progress bar
    progress.dismiss();

    Log.i("Async_GetAllTechSched", "dismiss progress");

    //launch the new form
    _Context.startActivity(intent);
}

一旦意图开始,它就无法到达新活动。我在onCreate中有一个LOG.i,它永远不会被击中。程序调用不会超时。当我尝试使用较少的数据返回相同的代码时,我没有得到错误。也就是说,当我将SELECT TOP 100放在将数据返回到异步任务的语句中时,它完全没问题。

我想我的问题是这样的 - 如果返回的数据小于1MB,为什么这会犯这个错误?如果是因为1MB的限制,我还能做些什么来绕过这个限制或以某种方式压缩返回的数据?

预期的设计是这个初始调用带回与这些名称相关联的名称和约会(管道分隔)。我在一个微调器中显示了一个独特的名称列表(取自arraylist)。当用户单击微调器中的名称时,它将启动一个新活动,该活动将显示与该名称关联的所有约会(同样,所有数据来自初始arraylist)。所有数据都在第一个异步任务中收集并被操纵。这样做是为了减少网络电话的数量。这个任务在两个Web服务调用中是可行的,所以如果这是答案而不是很好 - 我只是希望有一个不同/更好的方法来做到这一点,这样我可以保持Web服务调用有限并减少用户等待时间。

1 个答案:

答案 0 :(得分:2)

  

我还能做些什么来绕过这个限制

不确定。不要使用Intent个额外内容来传递数据。之一:

  • 将此重组为一个包含多个片段的活动,因此数据永远不会离开活动,或

  • 下载是由需要数据的活动完成的,还是

  • 非常非常小心使用静态数据成员从一个活动到下一个活动获取数据,为避免内存泄漏付出巨大努力