我面临一个问题,当我关闭我的应用程序时,我想停止服务并运行一个方法
新的 sendLogoutDetail().execute(AccountID);
更新我的数据库。我将方法放在 onDestroy() 中,但是当我结束我的应用程序时,Log Cat 充满了很多错误,我的方法根本没有运行。
这是我的安卓代码:
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
String AccountID = null;
Bundle extras = getIntent().getExtras();
if (extras != null){
AccountID = extras.getString("AccountID");
}
new sendLogoutDetail().execute(AccountID);
stopService(new Intent(this,getLocationService.class));
}
private class sendLogoutDetail extends AsyncTask<String, Void, String>
{
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressDialog= ProgressDialog.show(LoggedIn.this, "Ending Service","Loading..", true);
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
HttpPost request = new HttpPost(SERVICE_URI + "/DeleteLoginPool");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
JSONStringer getWifiInfo;
try {
getWifiInfo = new JSONStringer()
.object()
.key("staffLocate")
.object()
.key("AccountID").value(params[0])
.endObject()
.endObject();
StringEntity entity = new StringEntity(getWifiInfo.toString());
request.setEntity(entity);
// Send request to WCF service
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
progressDialog.dismiss();
}
}
还有我的日志猫:
>06-19 18:42:09.626: W/asset(22278): deep redirect failure from 0x01030117 => 0x0a0a0004, defStyleAttr=0x01010084, defStyleRes=0x0103008f, style=0x010302eb
>06-19 18:42:09.626: W/asset(22278): deep redirect failure from 0x01030117 => 0x0a0a0004, defStyleAttr=0x01010084, defStyleRes=0x0103008f, style=0x010302eb
>06-19 18:42:09.688: E/WindowManager(22278): Activity com.example.staffallocatorproject.LoggedIn has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{413f5790 V.E..... R.....I. 0,0-0,0} that was originally added here
>06-19 18:42:09.688: E/WindowManager(22278): android.view.WindowLeaked: Activity com.example.staffallocatorproject.LoggedIn has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{413f5790 V.E..... R.....I. 0,0-0,0} that was originally added here
>06-19 18:42:09.688: E/WindowManager(22278): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
>06-19 18:42:09.688: E/WindowManager(22278): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
>06-19 18:42:09.688: E/WindowManager(22278): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.Dialog.show(Dialog.java:281)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ProgressDialog.show(ProgressDialog.java:116)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ProgressDialog.show(ProgressDialog.java:99)
>06-19 18:42:09.688: E/WindowManager(22278): at com.example.staffallocatorproject.LoggedIn$sendLogoutDetail.onPreExecute(LoggedIn.java:57)
>06-19 18:42:09.688: E/WindowManager(22278): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
>06-19 18:42:09.688: E/WindowManager(22278): at android.os.AsyncTask.execute(AsyncTask.java:534)
>06-19 18:42:09.688: E/WindowManager(22278): at com.example.staffallocatorproject.LoggedIn.onDestroy(LoggedIn.java:45)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.Activity.performDestroy(Activity.java:5391)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1110)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3568)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3599)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ActivityThread.access$1200(ActivityThread.java:156)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
>06-19 18:42:09.688: E/WindowManager(22278): at android.os.Handler.dispatchMessage(Handler.java:99)
>06-19 18:42:09.688: E/WindowManager(22278): at android.os.Looper.loop(Looper.java:137)
>06-19 18:42:09.688: E/WindowManager(22278): at android.app.ActivityThread.main(ActivityThread.java:5233)
>06-19 18:42:09.688: E/WindowManager(22278): at java.lang.reflect.Method.invokeNative(Native Method)
>06-19 18:42:09.688: E/WindowManager(22278): at java.lang.reflect.Method.invoke(Method.java:511)
>06-19 18:42:09.688: E/WindowManager(22278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
>06-19 18:42:09.688: E/WindowManager(22278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
>06-19 18:42:09.688: E/WindowManager(22278): at dalvik.system.NativeStart.main(Native Method)
>06-19 18:42:09.719: E/<<myServiceRunner-onDestroy>>(22278): I am dead-3