public void onPostExecute(GenericTask task, TaskResult result) { mListView.onRefreshComplete(); // Page mPage = new Page(); // TODO 判断TaskReult的返回值是否ok if (result == TaskResult.OK) { if (page == 1) { mItems = mLoadDataTask.getShareItems(); mAdapter.setDataList(mItems); mListView.setAdapter(mAdapter); page = page + 1; } else { mItems = mLoadDataTask.getShareItems(); mAdapter.notifyDataSetChanged(); page = page + 1; } // ShowToast.showGetSuccess(FoodActivity.this); } else if (result == TaskResult.FAILED) { // img.setVisibility(View.VISIBLE); // mListView.setVisibility(View.GONE); // ShowToast.showGetFaile(SearchStoreActivity.this); ShowToast.showMessage(SearchShareActivity.this, "没有相关微分享,请输入其他搜索内容。"); } else if (result == TaskResult.IO_ERROR) { ShowToast.showMessage(SearchShareActivity.this, "没有相关微分享,请输入其他搜索内容。"); } else if (result == TaskResult.NO_MORE_DATA) { ShowToast.showNomoredata(SearchShareActivity.this); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tvchannelviewpager); JSONObject crittercismConfig = new JSONObject(); try { crittercismConfig.put( "shouldCollectLogcat", true); // send logcat data for devices with API Level 16 and higher } catch (JSONException je) { } // Crittercism.init(getApplicationContext(), "51ccf765558d6a0c25000003", crittercismConfig); /*Bundle extras = getIntent().getExtras(); currIndex = extras.getInt("type_id", 0); if(currIndex > listnumber) currIndex = 0; functionFlag = extras.getInt("sort_id", 2);*/ currIndex = TvDramaApplication.shIO.getInt("type_id", 0); if (currIndex > listnumber) currIndex = 0; functionFlag = TvDramaApplication.shIO.getInt("sort_id", 2); initViews(); loadTask = new LoadDataTask(); if (Build.VERSION.SDK_INT < 11) loadTask.execute(); else loadTask.executeOnExecutor(LoadDataTask.THREAD_POOL_EXECUTOR, 0); }
@Override protected void onDestroy() { // TODO Auto-generated method stub Log.e("onDestroy()", "onDestroy()"); if (null != mLoadDataTask && mLoadDataTask.getStatus() == LoadDataTask.Status.RUNNING) { mLoadDataTask.cancel(true); } super.onDestroy(); }
@Override public void onDestroy() { super.onDestroy(); if (loadTask != null && loadTask.getStatus() != AsyncTask.Status.FINISHED) { loadTask.closeProgressDilog(); loadTask.cancel(true); } if (updatetask != null && updatetask.getStatus() != AsyncTask.Status.FINISHED) { updatetask.closeProgressDilog(); updatetask.cancel(true); } }
private void loaddata() { /** 重要!!需要判断当前任务是否正在运行,否则重复执行会出错,典型的场景就是用户点击登录按钮多次 */ if (null != mLoadDataTask && mLoadDataTask.getStatus() == GenericTask.Status.RUNNING) return; mLoadDataTask = new LoadDataTask(); mLoadDataTask.setListener(mTaskListener); try { mLoadDataTask.execute(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } }
public boolean onKeyDown(int keyCode, KeyEvent event) { // 捕捉返回键 if (keyCode == KeyEvent.KEYCODE_BACK) { if (null != mLoadDataTask) { mLoadDataTask.cancel(true); mLoadDataTask = null; Log.e("cancel", "cancel"); mListView.onRefreshComplete(); return true; } } // return true; return super.onKeyDown(keyCode, event); }