Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android泄漏窗口-应用程序采用ANR状态_Android_Exception_Memory Leaks - Fatal编程技术网

Android泄漏窗口-应用程序采用ANR状态

Android泄漏窗口-应用程序采用ANR状态,android,exception,memory-leaks,Android,Exception,Memory Leaks,我正在使用一款使用谷歌地图的android应用程序。应用程序通常运行良好。我可以在日志中看到一些错误[如下] Logcat 08-28 15:37:36.945: E/WindowManager(21969): Activity com.kod.example.Find_Tab_MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40929cd8 that was origin

我正在使用一款使用谷歌地图的android应用程序。应用程序通常运行良好。我可以在日志中看到一些错误[如下]

Logcat

08-28 15:37:36.945: E/WindowManager(21969): Activity com.kod.example.Find_Tab_MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40929cd8 that was originally added here
08-28 15:37:36.945: E/WindowManager(21969): android.view.WindowLeaked: Activity com.kod.example.Find_Tab_MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40929cd8 that was originally added here
08-28 15:37:36.945: E/WindowManager(21969):     at android.view.ViewRoot.<init>(ViewRoot.java:263)
08-28 15:37:36.945: E/WindowManager(21969):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:171)
08-28 15:37:36.945: E/WindowManager(21969):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
08-28 15:37:36.945: E/WindowManager(21969):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.Dialog.show(Dialog.java:241)
08-28 15:37:36.945: E/WindowManager(21969):     at com.kod.example.MyProgressDialog.show(MyProgressDialog.java:36)
08-28 15:37:36.945: E/WindowManager(21969):     at com.kod.example.MyProgressDialog.show(MyProgressDialog.java:19)
08-28 15:37:36.945: E/WindowManager(21969):     at com.kod.example.MyProgressDialog.show(MyProgressDialog.java:14)
08-28 15:37:36.945: E/WindowManager(21969):     at com.kod.example.Find_Tab_MainActivity$LoadPlaces.onPreExecute(Find_Tab_MainActivity.java:129)
08-28 15:37:36.945: E/WindowManager(21969):     at android.os.AsyncTask.execute(AsyncTask.java:391)
08-28 15:37:36.945: E/WindowManager(21969):     at com.kod.example.Find_Tab_MainActivity.onCreate(Find_Tab_MainActivity.java:112)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-28 15:37:36.945: E/WindowManager(21969):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 15:37:36.945: E/WindowManager(21969):     at android.os.Looper.loop(Looper.java:130)
08-28 15:37:36.945: E/WindowManager(21969):     at android.app.ActivityThread.main(ActivityThread.java:3687)
08-28 15:37:36.945: E/WindowManager(21969):     at java.lang.reflect.Method.invokeNative(Native Method)
08-28 15:37:36.945: E/WindowManager(21969):     at java.lang.reflect.Method.invoke(Method.java:507)
08-28 15:37:36.945: E/WindowManager(21969):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-28 15:37:36.945: E/WindowManager(21969):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-28 15:37:36.945: E/WindowManager(21969):     at dalvik.system.NativeStart.main(Native Method)
08-28 15:37:36.945:E/WindowManager(21969):Activity com.kod.example.Find_Tab_main活动泄漏了window com.android.internal.policy.impl.PhoneWindow$DecorView@40929cd8原来是加在这里的
08-28 15:37:36.945:E/WindowManager(21969):android.view.WindowLeaked:Activity com.kod.example.Find_Tab_main活动已泄漏window com.android.internal.policy.impl.PhoneWindow$DecorView@40929cd8原来是加在这里的
08-28 15:37:36.945:E/WindowManager(21969):在android.view.ViewRoot(ViewRoot.java:263)上
08-28 15:37:36.945:E/WindowManager(21969):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:171)
08-28 15:37:36.945:E/WindowManager(21969):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
08-28 15:37:36.945:E/WindowManager(21969):在android.view.Window$LocalWindowManager.addView(Window.java:424)
08-28 15:37:36.945:E/WindowManager(21969):在android.app.Dialog.show(Dialog.java:241)
08-28 15:37:36.945:E/WindowManager(21969):位于com.kod.example.MyProgressDialog.show(MyProgressDialog.java:36)
08-28 15:37:36.945:E/WindowManager(21969):位于com.kod.example.MyProgressDialog.show(MyProgressDialog.java:19)
08-28 15:37:36.945:E/WindowManager(21969):位于com.kod.example.MyProgressDialog.show(MyProgressDialog.java:14)
08-28 15:37:36.945:E/WindowManager(21969):位于com.kod.example.Find_Tab_main活动$LoadPlaces.onPreExecute(Find_Tab_main活动.java:129)
08-28 15:37:36.945:E/WindowManager(21969):在android.os.AsyncTask.execute(AsyncTask.java:391)
08-28 15:37:36.945:E/WindowManager(21969):在com.kod.example.Find\u Tab\u MainActivity.onCreate(Find\u Tab\u MainActivity.java:112)
08-28 15:37:36.945:E/WindowManager(21969):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-28 15:37:36.945:E/WindowManager(21969):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-28 15:37:36.945:E/WindowManager(21969):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-28 15:37:36.945:E/WindowManager(21969):android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-28 15:37:36.945:E/WindowManager(21969):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-28 15:37:36.945:E/WindowManager(21969):在android.os.Handler.dispatchMessage(Handler.java:99)上
08-28 15:37:36.945:E/WindowManager(21969):在android.os.Looper.loop(Looper.java:130)
08-28 15:37:36.945:E/WindowManager(21969):位于android.app.ActivityThread.main(ActivityThread.java:3687)
08-28 15:37:36.945:E/WindowManager(21969):位于java.lang.reflect.Method.Invokenactive(本机方法)
08-28 15:37:36.945:E/WindowManager(21969):位于java.lang.reflect.Method.invoke(Method.java:507)
08-28 15:37:36.945:E/WindowManager(21969):位于com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-28 15:37:36.945:E/WindowManager(21969):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-28 15:37:36.945:E/WindowManager(21969):在dalvik.system.NativeStart.main(本机方法)
这是什么?我的应用程序工作正常,但有时会崩溃,总是抛出此错误

我的代码

package com.kod.example;

import java.util.List;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Button;

import com.google.android.maps.MapActivity;


public class Find_Tab_MainActivity extends MapActivity {

    // flag for Internet connection status
    Boolean isInternetPresent = false;

    Geocoder geocoder;

    String status;

    // Connection detector class
    ConnectionDetector cd;

    // Alert Dialog Manager
    AlertDialogManager alert = new AlertDialogManager();

    // Google Places
    GooglePlaces googlePlaces;

    // Places List
    PlacesList nearPlaces;

    Place reference;
    // GPS Location
    GPSTracker gps;
    double latitude;
    double longitude;
    // Button
    Button loginbtn;

    Place p;

    Intent i;

    // Progress dialog
    ProgressDialog pDialog;
    final Context context = this;

    String type,KEY_KEYWORD,KEY_TAG;



    // KEY Strings
    public static String KEY_REFERENCE = "reference"; // id of the place
    public static String KEY_NAME = "name"; // name of the place
    public static String KEY_VICINITY = "vicinity";
    public static String KEY_NUMBER = "formatted_phone_number";


    // Place area name

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

        cd = new ConnectionDetector(getApplicationContext());


        Intent entent = getIntent();

           type = entent.getExtras().getString("KEY_TYPES");
           KEY_KEYWORD = entent.getExtras().getString("KEY_KEYWORD");
           KEY_TAG = entent.getExtras().getString("KEY_TAG");


        // Check if Internet present
        isInternetPresent = cd.isConnectingToInternet();
        if (!isInternetPresent) {
            // Internet Connection is not present
            alert.showAlertDialog(Find_Tab_MainActivity.this, "Internet Connection Error",
                    "Please connect to working Internet connection", false);
            // stop executing code by return
            return;
        }

        // creating GPS Class object
        gps = new GPSTracker(this);

        // check if GPS location can get
        if (gps.canGetLocation()) {

        } else {
            // Can't get user's current location
            alert.showAlertDialog(Find_Tab_MainActivity.this, "GPS Status",
                    "Couldn't get location information. Please enable GPS",
                    false);
            // stop executing code by return
            return;
        }


        // calling background Async task to load Google Places
        // After getting places from Google all the data is shown in listview
        new LoadPlaces().execute();

        /** Button click event for shown on map */

            }

    /**
     * Background Async Task to Load Google places
     * */
    class LoadPlaces extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            MyProgressDialog.show(Find_Tab_MainActivity.this, "", ""); 
            }

        /**
         * getting Places JSON
         * */
        protected String doInBackground(String... args) {
            // creating Places class object
            googlePlaces = new GooglePlaces();

            try {
                // Separeate your place types by PIPE symbol "|"
                // If you want all types places make it as null
                // Check list of types supported by google
                String types = type; // Listing places only for park

                // Radius in meters - increase this value if you don't find any places
                double radius = 10000; // 1000 meters 

                if(KEY_TAG.equalsIgnoreCase("1")||KEY_TAG.equalsIgnoreCase("4")||KEY_TAG.equalsIgnoreCase("5"))
                {
                    // get nearest places
                    nearPlaces = googlePlaces.search(gps.getLatitude(),gps.getLongitude(), radius, types);
                }
                else if(KEY_TAG.equalsIgnoreCase("2")||KEY_TAG.equalsIgnoreCase("3"))
                {
                    // get nearest places
                    nearPlaces = googlePlaces.StreetGaragesearch(gps.getLatitude(), gps.getLongitude(), radius, types,KEY_KEYWORD); 
                }

                else if(KEY_TAG.equalsIgnoreCase("6"))
                {
                     String addressInput  = type;

                     geocoder = new Geocoder(Find_Tab_MainActivity.this);
                 List<Address> address;

                    address = geocoder.getFromLocationName(addressInput,1);
                         if (address == null) {
                             alert.showAlertDialog(Find_Tab_MainActivity.this, "Places Error",
                                        "Sorry error occured.",
                                        false);
                         }
                         else{
                         Address location = address.get(0);
                        latitude = location.getLatitude();
                        longitude = location.getLongitude();

                    nearPlaces = googlePlaces.Keywordsearch(latitude,longitude,radius+40000,"parking",type);
                         }

                    // get nearest places


            } 
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        /**
         * After completing background task Dismiss the progress dialoghis
         * and show the data in UI
         * Always use runOnUiThread(new Runnable()) to update UI from background
         * thread, otherwise you will get error
         * **/
        @SuppressWarnings("deprecation")
        protected void onPostExecute(String file_url) {
            try{
        // Get json response status
             status = nearPlaces.status;

            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {


                    if(status.equals("OK")){
                        // Successfully got places details
                        i = new Intent(getApplicationContext(),
                                MyPlacesMapActivity.class);
                        // Sending user current geo location

                        // passing near places to map activity
                        i.putExtra("near_places", nearPlaces);

                        //passing type to placemapactivity to identify the overlay icon
                        i.putExtra("KEY_TAG", KEY_TAG);

                        //passing place reference
                        i.putExtra("place_reference", reference);

                        // staring activity
                        startActivity(i);
                                }

                    else if(status.equals("ZERO_RESULTS")){
                        // Zero results found

                        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("No Results");

                        // Setting Dialog Message
                        alertDialog.setMessage("Sorry no places found. Try to change the location");

                        // Setting alert dialog icon
                            alertDialog.setIcon(R.drawable.fail);

                        // Setting OK Button
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Find_Tab_MainActivity.this.finish();
                            }
                        });

                        // Showing Alert Message
                        alertDialog.show();
                    }
                    else if(status.equals("UNKNOWN_ERROR"))
                    {

                        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("Error");

                        // Setting Dialog Message
                        alertDialog.setMessage("Sorry unknown error occured.");

                        // Setting alert dialog icon
                            alertDialog.setIcon(R.drawable.fail);

                        // Setting OK Button
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Find_Tab_MainActivity.this.finish();
                            }
                        });

                        // Showing Alert Message
                        alertDialog.show();

                    }
                    else if(status.equals("OVER_QUERY_LIMIT"))
                    {

                        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("Error");

                        // Setting Dialog Message
                        alertDialog.setMessage("Sorry query limit to is reached");

                        // Setting alert dialog icon
                            alertDialog.setIcon(R.drawable.fail);

                        // Setting OK Button
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Find_Tab_MainActivity.this.finish();
                            }
                        });

                        // Showing Alert Message
                        alertDialog.show();

                    }
                    else if(status.equals("REQUEST_DENIED"))
                    {

                        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("Error");

                        // Setting Dialog Message
                        alertDialog.setMessage("Sorry error occured. Request is denied");

                        // Setting alert dialog icon
                            alertDialog.setIcon(R.drawable.fail);

                        // Setting OK Button
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Find_Tab_MainActivity.this.finish();
                            }
                        });

                        // Showing Alert Message
                        alertDialog.show();

                    }
                    else if(status.equals("INVALID_REQUEST"))
                    {

                        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("Error");

                        // Setting Dialog Message
                        alertDialog.setMessage("Sorry error occured. Invalid Request");

                        // Setting alert dialog icon
                            alertDialog.setIcon(R.drawable.fail);

                        // Setting OK Button
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Find_Tab_MainActivity.this.finish();
                            }
                        });

                        // Showing Alert Message
                        alertDialog.show();
                    }
                    else
                    {

                        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("Error");

                        // Setting Dialog Message
                        alertDialog.setMessage("Sorry error occured.");

                        // Setting alert dialog icon
                            alertDialog.setIcon(R.drawable.fail);

                        // Setting OK Button
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Find_Tab_MainActivity.this.finish();
                            }
                        });

                        // Showing Alert Message
                        alertDialog.show();
                    }
                }
            });
        }catch(NullPointerException e){

            final AlertDialog alertDialog = new AlertDialog.Builder(context).create();

            // Setting Dialog Title
            alertDialog.setTitle("Error");

            // Setting Dialog Message
            alertDialog.setMessage("Requested place not found.");

            // Setting alert dialog icon
                alertDialog.setIcon(R.drawable.fail);

            // Setting OK Button
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Find_Tab_MainActivity.this.finish();
                }
            });

            // Showing Alert Message
            alertDialog.show();

        }

        }
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}
package com.kod.example;
导入java.util.List;
导入android.app.AlertDialog;
导入android.app.ProgressDialog;
导入android.content.Context;
导入android.content.DialogInterface;
导入android.content.Intent;
导入android.location.Address;
导入android.location.Geocoder;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.widget.Button;
导入com.google.android.maps.MapActivity;
公共类查找选项卡主活动扩展了MapActivity{
//Internet连接状态的标志
布尔值isInternetPresent=false;
地理编码器;
字符串状态;
//连接检测器类
连接检测器cd;
//警报对话框管理器
AlertDialogManager alert=新建AlertDialogManager();
//谷歌地点
GooglePlaces GooglePlaces;
//名额表
附近的地方;
地点参考;
//GPS定位
全球定位系统;
双纬度;
双经度;
//钮扣
按钮登录;
p位;
意图一;
//进度对话框
ProgressDialog;
最终上下文=此;
字符串类型、关键字、关键字标签;
//键串
公共静态字符串KEY\u REFERENCE=“REFERENCE”//位置的id
公共静态字符串KEY_NAME=“NAME”;//地点名称
公共静态字符串键\u neighborary=“neighborary”;
公共静态字符串键\u NUMBER=“格式化的\u电话号码”;
//地名
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cd=新连接检测器(getApplicationContext());
Intent entent=getIntent();
type=entent.getExtras().getString(“键类型”);
KEY_关键字=entent.getExtras().getString(“KEY_关键字”);
KEY_TAG=entent.getExtras().getString(“KEY_TAG”);
//检查互联网是否存在
isInternetPresent=cd.isConnectingToInternet();
如果(!isInternetPresent){
//Internet连接不存在
alert.showAlertDialog(查找选项卡\u MainActivity.this,“Internet连接错误”,
“请连接到正在工作的Internet连接”,错误);
//通过返回停止执行代码
返回;
}
//创建GPS类对象
gps=新的GPSTracker(本);
//检查是否可以获得GPS定位
if(gps.canGetLocation()){
}否则{
//
What is this leaked window? 
if(getActivity()!= null && !getActivity().isFinishing()){
            Dialog.show();
}
protected void onPostExecute(String file_url) {

    // your first line should be this 

    if ( MyProgressDialog!=null && MyProgressDialog.isShowing() ){
        MyProgressDialog.dismiss();
    }

    // rest of the code 
}