package com.jiuqi.njt.register; import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientContext; import com.jiuqi.njt.data.MyApp; import com.jiuqi.njt.util.Constants; import com.jiuqi.njt.util.RepairUtils; import com.jiuqi.njt.util.UIUtil; import android.app.Dialog; import android.content.Context; import android.os.AsyncTask; import android.util.Log; /** * 创建一个请求服务器对象 * @author joe * @param <T> * */ public class BaseTask<T> extends AsyncTask<Void, Void, T>{ private Context context; private MyApp application; private Class<?> manager; private TaskInterface allTaskInterface; private Dialog pd; private int dialogType = 5; private String message = ""; /** * 根据需求,创建一个请求服务器对象 * * @param context * @param manager * 想创建的管理对象 * @param allTaskInterface * 返回创建成功的管理对象接口 * @param dialogType * 显示的对话框类型 * 0:不显示对话框,1 :正在定位...2:正在获取天气...3:正在验证账号... * 4:正在提交数据...5:正在获取数据... 6:正在验证手机号码... */ public BaseTask(Context context, Class<?> manager, TaskInterface allTaskInterface,int dialogType) { super(); this.context = context; this.manager = manager; this.allTaskInterface = allTaskInterface; this.dialogType = dialogType; application = (MyApp) context.getApplicationContext(); } @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); if(0!=dialogType){ pd = RepairUtils.myShowDialog(context, dialogType); } } @SuppressWarnings("unchecked") @Override protected T doInBackground(Void... params) { // TODO Auto-generated method stub try { ClientContext context = application.getClientContext(); if (null == context) { context = ClientContext.getClientContext(Constants.SERVER_URL,Constants.ANONYMOUS, Constants.ANONYMOUS); application.setClientContext(context); } allTaskInterface.taskExecuteReturn(context.getManager(manager)); Log.e("--", "执行成功"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); message = "请求服务器失败"; } return null; } @Override protected void onPostExecute(T result) { // TODO Auto-generated method stub super.onPostExecute(result); RepairUtils.myRemoveDialog(pd); if(!"".equals(message)){ UIUtil.showMsg(context, message); } allTaskInterface.taskFinishReturn(true); } }