0
我有運行服務一旦這種IntentService代碼:運行Android功能反覆IntentService
protected void onHandleIntent(Intent intent) {
final ResultReceiver receiver = intent.getParcelableExtra("receiver");
String command = intent.getStringExtra("command");
Bundle b = new Bundle();
b.putString("results", results);
if(command.equals("query")) {
receiver.send(1, Bundle.EMPTY);
try {
results = sendGetMessage();
b.putString("results", results);
receiver.send(2, b);
} catch(Exception e) {
b.putString(Intent.EXTRA_TEXT, e.toString());
receiver.send(0, b);
}
}
this.stopSelf();
Log.d("ServiceFinished", "ServerConnection.java Service has finished");
}
我想,直到我停止服務我sendGetMessage()函數來反覆運行每5秒..我怎樣才能做它?
對不起忘了:我想ti每5秒重複運行一次.. – 2012-03-22 00:05:45
這也是一個不好的解決方案:系統可以選擇最終殺死你的線程... – 2012-03-22 00:35:38
@AsafNevo,我添加了一條線,它會讓它每5秒運行一次。 – ajacian81 2012-03-22 09:26:33