我正在开发APP发送短信号码,如果短信失败的Asynctask执行和检查时间间隔重新发送短信,但是,我所有的工作浪费,因为我不明白Asynctask 这里是我的码。短信重发+异步任务
异步类
class checkList extends AsyncTask<String, Void, Void> {
public Void doInBackground(String... p) {
while (true) {
already_running_async=true;
sms.sendTextMessage(phone_nr, null, "SmS Sending", sentPI, null);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (isCancelled()) break;
}
return null;
}
};
短信发送代码和错误处理
bol=false;
already_running_async=false;
check=false;
sms = SmsManager.getDefault();
if(!phone_nr.equals(""))
sms.sendTextMessage(phone_nr, null,"Sms body" , sentPI, null);
sendBroadcastReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode())
{
case Activity.RESULT_OK:
//sms sent if bol true cancel the Asynctask :)
if(bol){
new checkList().cancel(true);}
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
if(already_running_async==false){
new checkList().execute();
bol=true;}
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
if(already_running_async==false){
new checkList().execute();
bol=true;}
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
if(already_running_async==false){
new checkList().execute();
bol=true;}
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
if(already_running_async==false){
new checkList().execute();
bol=true;}
break;
}
}
};
registerReceiver(sendBroadcastReceiver , new IntentFilter(SENT));
问题: 任务启动,但任务仍然活着,并在10秒我多次发送短信也取消了取消,但asyntask在取得成功后没有取消短信发送
请帮助我还没有睡,因为这个问题对夜:(
问候
请说明你的实际问题是什么。文字没有发送吗?该任务是否不启动?是什么东西引发错误? – thegrinner 2012-08-09 12:13:55
你好,任务启动,但任务仍然活着,并在10秒后重复发送短信我也放了取消,但asyntask不成功取消发送成功后短信 – Fawad 2012-08-09 12:15:59