我想要一个 AsyncTask
在给定参数的情况下发送 SMS。 SMS 已正确发送,但我想显示 ProgressBar
直到 SMS 发送,然后将用户带到新 Activity 。我在互联网上查看示例,但我无法弄清楚我想用我的案例做什么。下面是我的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);
}
}
我很感激任何帮助。谢谢。
最佳答案
请检查源代码。
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);
}
}
我认为它对你有帮助。
谢谢
关于android - 使用 ProgressBar 和 AsyncTask 发送短信 |安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11039825/