目前应用程序中有一个打印的方法,比较耗费时间,页面上当点击打印后调用该方法时当文件比较大的时候出现了ANR,请问如何解决?谢谢各位了
代码如下:
//按钮点击后请求该方法,判断是否可以打印
class expenseMCoinByStudentId extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... strings) {
String url = HttpConstant.expenseMCoinByStudentId;
String postString = "studentId="+studentId+"&resourceType="+resourceType+"&resourceId="+resourceId+"&course="+course
+"&mchnId="+mchnId+"&expenseMCoin="+expenseMCoin+"&pageSize="+pageSize+"&pageCount="+zhang+"&resourceName="+resourceName
+"&errorBookName="+errorBookName+"&errorBookId="+errorBookId+"&qOrA="+qOrA;
LogUtils.e("expenseMCoinByStudentId:" , postString);
String json = HttpConnectionUtil.AccessUrlGET(getContext(),url+"?"+postString);
LogUtils.e("json:" , json);
return json;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
ApiResponse<String> info = JsonUtils.jsonToJavaBean(result, ApiResponse.class);
if (info.getCode() != null && info.getCode().equals("10000")) {
Map<String,String> orderInfo = JsonUtils.jsonToJavaBean(JSONArray.toJSONString(info.getData()), Map.class);
//LogUtils.e("orderId:" , orderInfo.get("orderId"));
CreateOrderParams createOrderParams = new CreateOrderParams();
createOrderParams.setStudentId(studentId);
createOrderParams.setOrderId(orderInfo.get("orderId"));
try{
//请求正常后进行这个比较耗时的打印,目前试过起一个线程执行打印程序还是会崩溃
//下边的这个方法内部封装别人的jar,给个文件的url进行自行下载和打印,没法做更多的修改
printPdf(createOrderParams);
} catch (Exception e) {
ToastUtil.showShort(getContext(),e.getMessage());
LogUtils.e("printErr",e.getMessage());
}
}
}
}