對不起,如果我的問題與其他人類似,但我沒有得到解決方案。AsyncTask是一個內部類:獲取onPostExecute()結果在服務
我有兩個類,MainActivity和SMSMonitorService。
AsyncTask是MainActivity的一個內部類。
我想獲得onPostExecute結果並通過短信發送。 sendReplySMS方法在SMSMonitorService上。
MainActivity.java
public class MainActivity extends ActionBarActivity {
//some code...
public class DownloadWebpageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
// params comes from the execute() call: params[0] is the url.
try {
return downloadUrl(urls[0]);
} catch (IOException e) {
return "Unable to retrieve web page. URL may be invalid.";
}
}
// onPostExecute displays the results of the AsyncTask.
@Override
protected void onPostExecute(String result) {
//Extract String between two delimiters
String finalResult = StringUtils.substringBetween(result, "extract\":\"", "\"}}}}");
String finalResponse = StringEscapeUtils.unescapeJava(finalResult);
textView.setText(finalResponse);
SMSMonitorService.sendReplySMS(SMSMonitorService.number, finalResponse); //sendReplySMS and number are declared static
}
}
SMSMonitorService.java
public class SMSMonitorService extends Service {
//some code...
public static void sendReplySMS(String number, String responseText) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(number, null, responseText, null, null);
}
//some code..
的短信從不發送。
我如何發送短信什麼包含onPostExecute結果?
非常感謝您的幫助。
'SMSMonitorService.number'occupy是什麼值? –
'號碼'是始發地址。 – androidBegginer