Android AsyncTask 联系人导入 new AsyncTask<ArrayList<ContactInfo>, Integer, ArrayL
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;
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);
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:Android AsyncTask实现异步处理任务的方法详解Android使用AsyncTask下载图片并显示进度条功能Android AsyncTask的优缺点详解android使用AsyncTask实现多线程下载实例Android中使用AsyncTask做下载进度条实例代码Android AsyncTask使用以及源码解析Android中使用AsyncTask实现文件下载以及进度更新提示Android AsyncTask详解及使用方法
--结束END--
本文标题: Android AsyncTask用法巧用实例代码
本文链接: https://lsjlt.com/news/22561.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0