2

我想在AsyncTask给定参数的情况下发送短信。SMS 正在正确发送,但我想在ProgressBar发送 SMS 之前显示一个,然后将用户带到一个新活动。我在互联网上查看了示例,但我无法弄清楚我想对我的案子做什么。下面是我的AsyncTask

public class sendSms extends AsyncTask<Void, Integer, Void>{            

         protected void onPreExecute() {
             pb.setVisibility(View.VISIBLE); //pb is the ProgressBar   
            }

        @Override
        protected Void doInBackground(Void... params) {
             SmsManager sms = SmsManager.getDefault();
             sms.sendTextMessage(phoneNumber, null, message, null, null);       
            return null;                
        }

        protected void onProgressUpdate(Integer... progress){
             //Not sure what to do here
        }

        protected void onPostExecute(){
            Intent intn = new Intent(CurrentActivity.this, NewActivity.class);
            startActivity(intn);
        }           
}

我很感激任何帮助。谢谢你。

4

1 回答 1

0

请检查源代码。

public class sendSms extends AsyncTask<Void, Integer, String>{            

         protected void onPreExecute() {
             pb.setVisibility(View.VISIBLE); //pb is the ProgressBar   
            }

        @Override
        protected Void doInBackground(Void... params) {
             SmsManager sms = SmsManager.getDefault();
             sms.sendTextMessage(phoneNumber, null, message, null, null);       
            return "Done";                
        }

        protected void onProgressUpdate(Integer... progress){
             //Not sure what to do here
        }

        protected void onPostExecute(String result){
if(result.equals("Done"))
        {
            pb.setVisibility(View.GONE);
            Intent intn = new Intent(this, NewActivity.class);
            startActivity(intn);
}
    }           

}

我认为它对你有帮助。

谢谢

于 2012-06-14T19:26:48.503 回答