91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android AsyncTask用法巧用實例代碼

發布時間:2020-10-21 14:28:01 來源:腳本之家 閱讀:178 作者:lqh 欄目:移動開發

Android AsyncTask

聯系人導入

 new AsyncTask<ArrayList<ContactInfo>, Integer, ArrayList<ContactInfo>>() {
                    @Override
                    protected void onPreExecute() {
                      super.onPreExecute();
                      if (importingDialog != null)
                        importingDialog.show();
                    }

                    @Override
                    protected ArrayList<ContactInfo> doInBackground(ArrayList<ContactInfo>... 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<ContactInfo> contactInfos) {
                      final ArrayList<String> names = new ArrayList<String>();
                      final ArrayList<String> numbers = new ArrayList<String>();
                      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<ContactInfo>());

聯系人刪除

new LauncherContactDeleAsyncTask(mActivity, contactInfosDeles).execute(new ArrayList<String>());

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<ArrayList<String>, Integer, ArrayList<String>> {
  private Context mContext = null;
  private ArrayList<ContactInfo> deleteListContacts;//總數
  private ContactInsertHelper contactInsertHelper;

  final ArrayList<String> deleContactPhones = new ArrayList<>();

  private ImportingDialog importingDialog = null;
  int deleCount = 0;
  int deleAllCount = 0;

  public LauncherContactDeleAsyncTask(Context mContext, ArrayList<ContactInfo> 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<String> doInBackground(ArrayList<String>... params) {
    for (ContactInfo member : deleteListContacts) {
      if (member.isCheck()) {
        //刪除聯系人
        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<String> 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);
  }
}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

乳源| 达孜县| 响水县| 葵青区| 吴川市| 滨州市| 慈利县| 武威市| 连江县| 特克斯县| 尤溪县| 运城市| 延川县| 琼中| 辉南县| 伊川县| 蚌埠市| 巴东县| 平凉市| 嘉黎县| 绥德县| 陆川县| 海口市| 宾阳县| 七台河市| 巩留县| 应用必备| 马公市| 富平县| 石泉县| 牡丹江市| 隆尧县| 永清县| 丹巴县| 垦利县| 平阳县| 喀喇| 长岛县| 达日县| 苍山县| 礼泉县|