2

I have a method called requestLocation, thats starting a progress dialog. I am calling this method from onResume();

my method:

public void requestLocation() {
    try { 
        progressDialog = ProgressDialog.show(this, "", "Obtaining Location Service", true);
    }
    catch(Exception e) {

    }

    updates=0;
    startingLocal = null;
    latestLocal = null;
    gps = null;
    gps = new KNLocationService(this);
    gps.setParent(this);
    // check if GPS enabled
    if (gps.canGetLocation()) {

        double latitude = gps.getLatitude();
        double longitude = gps.getLongitude();

        //progressDialog.dismiss();
        //locationServiceText.setText("Aquiring location");

    } else {
        try { 
            progressDialog.dismiss();
        } catch (Exception e) {

        }

        locationServiceText.setText("No LocationService Provided");
    }

}

but i am getting the following error that i am assuming is because of the progress dialog, but i can't seem to find out what exactly is causing it..

05-28 09:50:12.615: E/WindowManager(13774): Activity com.KingNozzle.KNAugmentedRealityActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@428a6f00 that was originally added here
05-28 09:50:12.615: E/WindowManager(13774): android.view.WindowLeaked: Activity com.KingNozzle.KNAugmentedRealityActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@428a6f00 that was originally added here
05-28 09:50:12.615: E/WindowManager(13774):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
05-28 09:50:12.615: E/WindowManager(13774):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
05-28 09:50:12.615: E/WindowManager(13774):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
05-28 09:50:12.615: E/WindowManager(13774):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
05-28 09:50:12.615: E/WindowManager(13774):     at android.view.Window$LocalWindowManager.addView(Window.java:547)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.Dialog.show(Dialog.java:277)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ProgressDialog.show(ProgressDialog.java:116)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ProgressDialog.show(ProgressDialog.java:99)
05-28 09:50:12.615: E/WindowManager(13774):     at com.KingNozzle.KNAugmentedRealityActivity.requestLocation(KNAugmentedRealityActivity.java:494)
05-28 09:50:12.615: E/WindowManager(13774):     at com.KingNozzle.KNAugmentedRealityActivity.onResume(KNAugmentedRealityActivity.java:162)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.Activity.performResume(Activity.java:5082)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-28 09:50:12.615: E/WindowManager(13774):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 09:50:12.615: E/WindowManager(13774):     at android.os.Looper.loop(Looper.java:137)
05-28 09:50:12.615: E/WindowManager(13774):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-28 09:50:12.615: E/WindowManager(13774):     at java.lang.reflect.Method.invokeNative(Native Method)
05-28 09:50:12.615: E/WindowManager(13774):     at java.lang.reflect.Method.invoke(Method.java:511)
05-28 09:50:12.615: E/WindowManager(13774):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-28 09:50:12.615: E/WindowManager(13774):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-28 09:50:12.615: E/WindowManager(13774):     at dalvik.system.NativeStart.main(Native Method)

I doesn't seem to crash the app but still i'd like to correct this.

OptimizedQuery
  • 1,262
  • 11
  • 21
erik
  • 4,946
  • 13
  • 70
  • 120

2 Answers2

4

You have to dismiss dialog:

@Override
protected void onDestroy() {
    super.onDestroy();
    progressDialog.dismiss();
}
Michał Jurczuk
  • 3,728
  • 4
  • 32
  • 56
1
if (gps.canGetLocation())
   // Then progress dialog will not be dismissed.

This is causing the leak. Dismiss the dialog when the tasks are done.

stinepike
  • 54,068
  • 14
  • 92
  • 112
  • even if i don't want to dismiss it there, in a gps updated method, I still want to display it with a different message? – erik May 28 '13 at 14:08
  • @erik. no problem .. just dismiss the dialog when all tasks are finished.. i am sure that you don't want to show the dialog for infinity. The leak is shown because you havne't dismiss the dialog. If you want to show in activity lifetime then dismiss it at onPause – stinepike May 28 '13 at 14:10