活动有泄漏窗口

时间:2013-10-12 20:46:40

标签: android android-asynctask

当我尝试运行我的应用程序时,我得到以下异常。

我不知道为什么它显示我的窗户是泄漏 我找到了很多解决方案,但没有帮助我。

10-13 02:15:07.154: E/WindowManager(13500): android.view.WindowLeaked: Activity com.se7enlabs.dishoom.SplashActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{424ebf90 V.E..... R.....ID 0,0-720,323} that was originally added here
10-13 02:15:07.154: E/WindowManager(13500):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
10-13 02:15:07.154: E/WindowManager(13500):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
10-13 02:15:07.154: E/WindowManager(13500):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-13 02:15:07.154: E/WindowManager(13500):     at android.app.Dialog.show(Dialog.java:281)
10-13 02:15:07.154: E/WindowManager(13500):     at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
10-13 02:15:07.154: E/WindowManager(13500):     at com..SplashActivity.buildAlertMessageNoGps(SplashActivity.java:101)
10-13 02:15:07.154: E/WindowManager(13500):     at com..SplashActivity.access$2(SplashActivity.java:81)
10-13 02:15:07.154: E/WindowManager(13500):     at com..SplashActivity$LocationUpdator.doInBackground(SplashActivity.java:198)
10-13 02:15:07.154: E/WindowManager(13500):     at com..SplashActivity$LocationUpdator.doInBackground(SplashActivity.java:1)
10-13 02:15:07.154: E/WindowManager(13500):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-13 02:15:07.154: E/WindowManager(13500):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-13 02:15:07.154: E/WindowManager(13500):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-13 02:15:07.154: E/WindowManager(13500):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-13 02:15:07.154: E/WindowManager(13500):     at java.lang.Thread.run(Thread.java:838)

这是我的代码以供更多参考。

    new LocationUpdator().execute();

private void buildAlertMessageNoGps() {
    alert = new AlertDialog.Builder(SplashActivity.this);
    alert.setMessage(   "Yout GPS seems to be disabled, do you want to enable it?")
            .setCancelable(false)
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                        public void onClick(
                                @SuppressWarnings("unused") final DialogInterface dialog,
                                @SuppressWarnings("unused") final int id) {

                            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            fromGPSMenu = 1;
                        }
                    })
            .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    Log.i("TESTING KEYBOARD","Showing on Clicking no ");
                    dontWantToEnableGPS = true;                     
                }
            });     
    alert.show();
}

public class LocationUpdator extends AsyncTask<Void, Void, Location> {
     Location location123 = null;



    @Override
    protected Location doInBackground(Void... arg0) {

        Looper.prepare();
        mThreadLooper = Looper.myLooper();          
        locationListener = new LocationListener() 
         {
         private String subLocality;
        @Override 
         public void onLocationChanged(Location location1) { 

             location123 =  location1; 
             userLocationLat = location1.getLatitude();
             userLocationlong = location1.getLongitude();           



             if(mThreadLooper != null)
                mThreadLooper.quit();
             //Stopping Request for Location
             if(manager!=null)
                 manager.removeUpdates(locationListener);
         } 

        String status="success";


        isAppOpen = true;
        if(isAppOpen)
        {               
                status = "networkonly"; 
                manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10, locationListener);

            if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                // if GPS provider is not enable then popup alertbox
                buildAlertMessageNoGps();
            } else {        
                // if gps is one then start searching                    
                status = "networkandgps";
                manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000,1000,  locationListener); 
            }
        }
        Log.i("STatus TEST","IS APP OPEN "+isAppOpen+" Status "+status);

        /*
         * set isAppOpen is false after getting location
         */

        /*
         * Get location (lat-long) from sharedpreference to further use
         */

        if (userLocationLat == 0.0 && userLocationlong == 0.0) {
            /*
             *  if lat-long is 0 or null then start searching using
             *  GPS Provider or Network Provider
             */

            manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Log.i("TEST","Starting Network Provider");
            manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10,locationListener);
            if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                //buildAlertMessageNoGps();
                ;
            } else {
                manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100000,100000,locationListener);               
            }
        } else {
            // set lat-long value in getset class for use of another activity

            manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10,locationListener);            
        }

         Looper.loop();
        return location123;
    }

    @Override
    protected void onPostExecute(Location result) {


        //progressDialog.dismiss();
        if(result!=null)
        {               
            Log.i("TESTING SPLASH","Lat3 "+userLocationLat);
            Log.i("TESTING SPLASH ","Long3 "+userLocationlong);

            startApplication();         

        }           

 }
 }

我真的不明白为什么我会收到这个错误。

1 个答案:

答案 0 :(得分:0)

doInBackground的{​​p> AsyncTask正在工作线程中运行,而不是在主线程上运行。您正在此线程中调用buildAlertMessageNoGPS()。您必须在onProgressUpdate()onPostExecute()onCancelled()中进行调用。这些方法在主线程上运行