2013-03-15 27 views
0

我有我的应用程序的问题,我得到我的android手机的GPS位置然后有坐标后,我想通过该数据到我的web服务,但我遇到这个错误,在本地主机中它运行完美无瑕。ecountering leaker窗口,虽然试图通过GPS坐标web服务

这是我得到的错误:

**

03-15 18:43:45.856: E/WindowManager(1906): Activity com.example.projectthesis.LocationPassing has leaked window [email protected] that was originally added here 
03-15 18:43:45.856: E/WindowManager(1906): android.view.WindowLeaked: Activity com.example.projectthesis.LocationPassing has leaked window [email protected] that was originally added here 
03-15 18:43:45.856: E/WindowManager(1906): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344) 
03-15 18:43:45.856: E/WindowManager(1906): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267) 
03-15 18:43:45.856: E/WindowManager(1906): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215) 
03-15 18:43:45.856: E/WindowManager(1906): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140) 
03-15 18:43:45.856: E/WindowManager(1906): at android.view.Window$LocalWindowManager.addView(Window.java:537) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.Dialog.show(Dialog.java:278) 
03-15 18:43:45.856: E/WindowManager(1906): at com.example.projectthesis.LocationPassing$phpconnect.onPreExecute(LocationPassing.java:74) 
03-15 18:43:45.856: E/WindowManager(1906): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561) 
03-15 18:43:45.856: E/WindowManager(1906): at android.os.AsyncTask.execute(AsyncTask.java:511) 
03-15 18:43:45.856: E/WindowManager(1906): at com.example.projectthesis.LocationPassing.onCreate(LocationPassing.java:58) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.Activity.performCreate(Activity.java:4465) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.ActivityThread.access$600(ActivityThread.java:123) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
03-15 18:43:45.856: E/WindowManager(1906): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-15 18:43:45.856: E/WindowManager(1906): at android.os.Looper.loop(Looper.java:137) 
03-15 18:43:45.856: E/WindowManager(1906): at android.app.ActivityThread.main(ActivityThread.java:4424) 
03-15 18:43:45.856: E/WindowManager(1906): at java.lang.reflect.Method.invokeNative(Native Method) 
03-15 18:43:45.856: E/WindowManager(1906): at java.lang.reflect.Method.invoke(Method.java:511) 
03-15 18:43:45.856: E/WindowManager(1906): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
03-15 18:43:45.856: E/WindowManager(1906): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
03-15 18:43:45.856: E/WindowManager(1906): at dalvik.system.NativeStart.main(Native Method) 

**

,这是我的课:

**

public class LocationPassing extends Activity{ 
    TextView txtLatitude; 
    TextView txtLongitude; 

    public static String strLat; 
    public static String strLong; 

    // ** This declarations was for passing of data to web service 
     // Progress Dialog 
     private ProgressDialog pDialog; 
     // JSONParser Object creation 
     JSONParser jsonParser = new JSONParser(); 
     // url to pass location to web 
      private static String url_create_product = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx/location_adding.php"; 
     //private static String url_create_product = "http://10.0.2.2/TheCalling/location_adding.php"; 

     // JSON Node names 
     private static final String TAG_SUCCESS = "success"; 
     private static final String TAG_PID = "pid"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.locationpassing); 

     txtLatitude = (TextView) findViewById(R.id.txtLatitude); 
     txtLongitude = (TextView) findViewById(R.id.txtLongitude); 

     strLat = Double.toString(Mapping2.ILatitude); 
     strLong = Double.toString(Mapping2.ILongitude); 

     this.txtLatitude.setText(strLat); 
     this.txtLongitude.setText(strLong); 

     new phpconnect().execute(); 

    } 

    class phpconnect extends AsyncTask<String, String, String> { 
     /** 
     * Before starting background thread Show Progress Dialog 
     * */ 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      pDialog = new ProgressDialog(LocationPassing.this); 
      pDialog.setMessage("Logging in.."); 
      pDialog.setIndeterminate(false); 
      pDialog.setCancelable(true); 
      pDialog.show(); 
     } 
     @Override 
     protected String doInBackground(String... args) { 
      String strLatitude = strLat; 
      String strLongitude = strLong; 

      String.valueOf(strLatitude); 
      String.valueOf(strLongitude); 

      // Building parameters 
      List<NameValuePair> params = new ArrayList<NameValuePair>(); 
      params.add(new BasicNameValuePair("latitude", strLatitude)); 
      params.add(new BasicNameValuePair("longitude", strLongitude)); 
      // getting JSON Object 
      // Note that create product url accepts POST method 
      JSONObject json = jsonParser.makeHttpRequest(url_create_product, 
        "POST", params); 
      // check log cat fro response 
      Log.d("Create Response", json.toString()); 
      try { 
       int success = json.getInt(TAG_SUCCESS); 
       if (success == 1) { 
        // successfully updated 
        Intent i = new Intent(getApplicationContext(), 
          Mapping2.class); 

        startActivity(i); 
        // closing this screen 
        finish(); 
       } else { 
        // failed to create product 
       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
      return null; 
     } 
    } 
} 

**

谢谢你们提前。

回答

0

您在onPreExecute中创建了一个对话框,但不要在onPostExecute中关闭它。

你的AysncTask完成和pDialog超出范围(它被销毁),但窗口仍然在屏幕上,因此泄漏。

在开始另一项活动或致电finish()之前,您还需要将其解雇。

另外这款因此,如果您的活动被迫到后台并重新它,如果你需要它的解雇,在onResume()

@Override 
public void onPause(){ 

    super.onPause(); 

    if(pDialog != null){ 
     pDialog.dismiss(); 
    }   

    ... 

} 

基本上添加到onPause(),不留在屏幕上,如果对话框您的任务完成或您离开活动。

+0

非常感谢你,现在没有窗户泄漏。 :)不幸的是,通过的部分只是不工作。无论如何,谢谢 – MakAdin 2013-03-15 19:10:33

+0

不客气。除了问题之外,您可能还想单击Tick以将其标记为正确的答案,以便其他人可以在未来找到答案,并且我会得到一点时间帮助的奖励;) – Simon 2013-03-15 19:14:15