在Android应用程序中,我想从doInBackground()方法返回JSONObject到onPostExecute()方法.
这是代码:
这是代码:
private class AddAsyncTask extends AsyncTask<String,Void,String> { JSONObject jsonObjRecv; String result; @Override protected JSONObject doInBackground(JSONObject... params) { AssetObj assetObj = new AssetObj(); assetObj.setAssetName(txtname.getText().toString()); assetObj.setMobileNo(txtmobile.getText().toString()); assetObj.setOwnerId(myApp.getOwnerId()); assetObj.setStartTime(startTime.getText().toString()); assetObj.setEndTime(endTime.getText().toString()); assetObj.setInterval(interval.getText().toString()); JSONObject jsonObjRecv = SyncService.AddNewAssetRequest(assetObj); return jsonObjRecv; } protected void onPostExecute(JSONObject obj){ if(obj != null) { //do something }
我试过这段代码我得到了错误.是否可以从doInBackground()方法返回JSONObject到onPostExecute()方法?
编辑:
原文链接:https://www.f2er.com/json/288531.html这可以帮到你,
private class AddAsyncTask extends AsyncTask<String,JSONOnject> { JSONObject jsonObjRecv; String result; @Override protected JSONObject doInBackground(String... params) { AssetObj assetObj = new AssetObj(); assetObj.setAssetName(txtname.getText().toString()); assetObj.setMobileNo(txtmobile.getText().toString()); assetObj.setOwnerId(myApp.getOwnerId()); assetObj.setStartTime(startTime.getText().toString()); assetObj.setEndTime(endTime.getText().toString()); assetObj.setInterval(interval.getText().toString()); JSONObject jsonObjRecv = SyncService.AddNewAssetRequest(assetObj); } protected void onPostExecute(JSONObject obj){ if(obj != null) { //do something }
这是明确的,
private class AddAsyncTask extends AsyncTask<What type of input you need to pass to doInBackground(),What type of return value you need to return to onPostExcute()>
可能你不需要在方法声明中更改返回值和参数.
只需创建以下行
private class AddAsyncTask extends AsyncTask<String,JSONOnject>
private class AddAsyncTask extends AsyncTask<String,JSONOnject>