当我按下模拟器的按钮时,我收到此异常。请告诉您这个错误的类型是什么。如何解决此错误
10-23 01:22:37.435: E/WindowManager(9185): Activity com.firstgroup.applicationload.Appliacationload has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d25790 G.E..... R.....ID 0,0-729,324} that was originally added here
10-23 01:22:37.435: E/WindowManager(9185): android.view.WindowLeaked: Activity com.firstgroup.applicationload.Appliacationload has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d25790 G.E..... R.....ID 0,0-729,324} that was originally added here
10-23 01:22:37.435: E/WindowManager(9185): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
10-23 01:22:37.435: E/WindowManager(9185): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
10-23 01:22:37.435: E/WindowManager(9185): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.Dialog.show(Dialog.java:281)
10-23 01:22:37.435: E/WindowManager(9185): at com.firstgroup.webservice.RequestTask.onPreExecute(RequestTask.java:36)
10-23 01:22:37.435: E/WindowManager(9185): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
10-23 01:22:37.435: E/WindowManager(9185): at android.os.AsyncTask.execute(AsyncTask.java:534)
10-23 01:22:37.435: E/WindowManager(9185): at com.firstgroup.applicationload.Appliacationload.onCreate(Appliacationload.java:37)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.Activity.performCreate(Activity.java:5104)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-23 01:22:37.435: E/WindowManager(9185): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 01:22:37.435: E/WindowManager(9185): at android.os.Looper.loop(Looper.java:137)
10-23 01:22:37.435: E/WindowManager(9185): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-23 01:22:37.435: E/WindowManager(9185): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 01:22:37.435: E/WindowManager(9185): at java.lang.reflect.Method.invoke(Method.java:511)
10-23 01:22:37.435: E/WindowManager(9185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-23 01:22:37.435: E/WindowManager(9185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-23 01:22:37.435: E/WindowManager(9185): at dalvik.system.NativeStart.main(Native Method)
这是我的主要活动
package com.firstgroup.applicationload;
public class Appliacationload extends Activity implements WebserviceCallBack{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appliacationload);
RequestTask callWebService=new RequestTask();
callWebService.setObserver(this);
callWebService.execute(ConstantVariable.dashboardWebServiceURL+"a/"+"arrival"+"?crsCode=vic");
}
@Override
public void getWebserviceResponse(InputStream response) {
// TODO Auto-generated method stub
}
}
public class RequestTask extends AsyncTask<String, String, InputStream>{
private WebserviceCallBack callBack;
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
progressDialog= new ProgressDialog((Context) callBack);
super.onPreExecute();
progressDialog.setTitle("Please Wait...");
progressDialog.setMessage("Webservice Call...");
progressDialog.setCancelable(true);
progressDialog.show();
}
@Override
protected InputStream doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
/*Reader reader = new InputStreamReader(response.getEntity().getContent());
Gson gson = new Gson();
Holder response1 = gson.fromJson(reader, Holder.class);
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();*/
return response.getEntity().getContent();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
//TODO Handle problems..\
progressDialog.hide();
} catch (IOException e) {
//TODO Handle problems..
progressDialog.hide();
}
return null;
}
@Override
protected void onPostExecute(InputStream result) {
super.onPostExecute(result);
//Do anything with response..
progressDialog.hide();
progressDialog=null;
if(callBack!=null){
callBack.getWebserviceResponse(result);
}
}
public void setObserver(WebserviceCallBack callback){
callBack=callback;
}
}
json观察员:
public interface WebserviceCallBack {
public void getWebserviceResponse(InputStream result);
}
I just
打电话给网络服务。我的电话回复得到了回复,但当我按下它时会崩溃为什么?
答案 0 :(得分:1)
<强>更新强>
使用ProgressDialog.hide()仅将其隐藏在屏幕上并且不会将其删除, 意味着对话框仍然存在于窗口中,只是它不可见。
当您的活动完成时,即按下后退按钮时,您需要自己删除任何对话框。因此,请确保在退出活动时调用ProgressDialog.dismiss()。
简而言之,您试图在Activity中显示一个不再存在或具有窗口焦点的对话框。
我可以看到你正在尝试运行RequestTask,我可以猜测在它的onPreExecute方法中有一个你想要显示的ProgressDialog。
根据您的目的,您可以选择一些方法来避免此问题:
如果您确实需要启动此任务,即使您的活动没有焦点, 你可以简单地删除触及AsyncTask的onPreExecute,onProgressUpdate和onPostExecute中的UI线程的任何内容。然后,任务将在后台静默运行。
与上一个选项类似,您可以创建一个服务来在后台完成工作。
最后,如果您的活动暂停,您也可以选择不启动任务。