Android AsyncTask
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名注冊、虛擬空間、營銷軟件、網(wǎng)站建設(shè)、盧氏網(wǎng)站維護、網(wǎng)站推廣。
聯(lián)系人導(dǎo)入
new AsyncTask, Integer, ArrayList >() { @Override protected void onPreExecute() { super.onPreExecute(); if (importingDialog != null) importingDialog.show(); } @Override protected ArrayList doInBackground(ArrayList ... params) { int importCount = 0; for (ContactInfo member : importListContact) { if (member.isCheck()) { importCount++; contactInsertHelper.insertSysContacts2Xphone(member); params[0].add(member); publishProgress(importCount); } } return params[0]; } @Override protected void onProgressUpdate(Integer... values) { importingDialog.notifyByteProgress(count, values[0]); } @Override protected void onPostExecute(ArrayList contactInfos) { final ArrayList names = new ArrayList (); final ArrayList numbers = new ArrayList (); for (ContactInfo contactInfo : contactInfos) { for (int i = 0; i < contactInfo.getPhones().size(); i++) { numbers.add(contactInfo.getPhones().get(i).replaceAll(" ", "")); names.add(contactInfo.getName()); } } Intent intent = new Intent("com.godinsec.importcomplete"); intent.putStringArrayListExtra("numbers", numbers); intent.putStringArrayListExtra("names", names); ImportContactActivity.this.sendBroadcast(intent); Intent updateIntent = new Intent("com.godinsec.update.syscontacts"); ImportContactActivity.this.sendBroadcast(updateIntent); handler.sendEmptyMessage(0); } }.execute(new ArrayList ());
聯(lián)系人刪除
new LauncherContactDeleAsyncTask(mActivity, contactInfosDeles).execute(new ArrayList());
package com.godinsec.contacts.core; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import com.godinsec.contacts.R; import com.godinsec.contacts.contactHelper.ContactInsertHelper; import com.godinsec.contacts.db.ApplicationSQLManger; import com.godinsec.contacts.dialog.ImportingDialog; import com.godinsec.contacts.model.ContactInfo; import java.util.ArrayList; /** * Created by Safly on 2016/9/23. */ public class LauncherContactDeleAsyncTask extends AsyncTask, Integer, ArrayList > { private Context mContext = null; private ArrayList deleteListContacts;//總數(shù) private ContactInsertHelper contactInsertHelper; final ArrayList deleContactPhones = new ArrayList<>(); private ImportingDialog importingDialog = null; int deleCount = 0; int deleAllCount = 0; public LauncherContactDeleAsyncTask(Context mContext, ArrayList contactInfos) { this.mContext = mContext; this.deleteListContacts = contactInfos; contactInsertHelper = new ContactInsertHelper(mContext); } @Override protected void onPreExecute() { super.onPreExecute(); importingDialog = new ImportingDialog(mContext,mContext.getResources().getString(R.string.gsettings_dele_contacts)); importingDialog.setCanceledOnTouchOutside(false); if (importingDialog != null){ importingDialog.show(); } for (ContactInfo member : deleteListContacts) { if (member.isCheck()) { deleAllCount++; } } } @Override protected ArrayList doInBackground(ArrayList ... params) { for (ContactInfo member : deleteListContacts) { if (member.isCheck()) { //刪除聯(lián)系人 long contactServerFlag = ApplicationSQLManger.getInstance().getContactServerFlagByLauncherContact(mContext, member); params[0].add(String.valueOf(contactServerFlag)); deleCount += contactInsertHelper.delete(mContext, member); //傳遞要刪除的號碼 for (String phone : member.getPhones()) { if (deleContactPhones != null) { deleContactPhones.add(phone); } } publishProgress(deleCount); } } return params[0]; } @Override protected void onProgressUpdate(Integer... values) { importingDialog.notifyByteProgress(deleAllCount, values[0]); } @Override protected void onPostExecute(ArrayList contactIds) { super.onPostExecute(contactIds); if (importingDialog.isShowing()) { importingDialog.dismiss(); } Intent updateIntent = new Intent("com.godinsec.update.syscontacts"); mContext.sendBroadcast(updateIntent); Intent intent = new Intent("com.godinsec.delcontact"); intent.putStringArrayListExtra("numbers", deleContactPhones); mContext.sendBroadcast(intent); } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!