我用完成()
在我的MainActivity結束我的應用程序解決我的問題(!可能不是一個真正的問題),我用的Robospice服務:
private final class LogoutListener implements PendingRequestListener<String> {
@Override
public void onRequestFailure(SpiceException spiceException) {
Log.e(TAG, spiceException.getMessage());
}
@Override
public void onRequestSuccess(String result) {
// nothing special
}
@Override
public void onRequestNotFound() {
Log.w(TAG, "Not found");
}
}
private void Alarm_Logout(boolean exit) {
Logout request = new Logout(url);
spiceManager.execute(request, new LogoutListener());
this.finish();
}
而且Lougout類:
public class Logout extends OkHttpSpiceRequest<String> {
private String url_logout;
public Logout(String url) {
super(String.class);
this.url_logout = url;
}
@Override
public String loadDataFromNetwork() throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url_logout)
.build();
Response response = client.newCall(request).execute();
return "ok";
}
}
之前,我關閉了應用程序與System.exit(0)在onRequestSuccess,所以我不得不等待註銷完成。現在應用程序關閉(與完成()),但註銷繼續在後臺,然後,當完成後,服務完成...
謝謝,我會嘗試... – Christian