当前位置: 首页 > 知识库问答 >
问题:

我的活动泄露了窗口,我找不到解决方案

何星鹏
2023-03-14

下面是我的密码

    public class CalendarView extends Activity {

       ArrayList<String> start_time,end_time;
        String doctor_id ,  hospital_id,da_id,status,date,time_interval,appointment_type,no_of_patient,doctor_name,specialty,hospital_name;
        public GregorianCalendar month, itemmonth;// calendar instances.
        String temp_start,temp_end;
        public CalendarAdapter adapter;// adapter instance
        public Handler handler;// for grabbing some event values for showing the dot
        // marker.
        public ArrayList<String> items,items2; // container to store calendar items which
        // needs showing the event marker
        ProgressDialog pDialog;

    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> productsList;

    private static String url_get_appointment = "http://pupqc.net/android_connect/get_appointments.php";

    private static final String TAG_SUCCESS = "success";
    private static final String TAG_APPOINTMENTS = "appointments";
    private static final String TAG_DA_ID = "da_id";
    private static final String TAG_STATUS = "status";
    private static final String TAG_DATE = "date";
    private static final String TAG_START_TIME = "start_time";
    private static final String TAG_END_TIME = "end_time";
    private static final String TAG_TIME_INTERVAL = "time_interval";
    private static final String TAG_APPOINTMENT_TYPE = "appointment_type";
    private static final String TAG_NO_OF_PATIENT = "no_of_patient";
    private static final String TAG_DOCTOR_NAME = "doctor_name";
    private static final String TAG_SPECIALTY = "specialty";
    private static final String TAG_HOSPITAL_NAME = "hospital_name";

    JSONArray products = null;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar);
        Locale.setDefault( Locale.US );
        month = (GregorianCalendar) GregorianCalendar.getInstance();
        itemmonth = (GregorianCalendar) month.clone();

        items = new ArrayList<String>();
        items2 = new ArrayList<String>();
        adapter = new CalendarAdapter(this, month);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(adapter);

        handler = new Handler();
        handler.post(calendarUpdater);


        //Getting Information

        doctor_id=getIntent().getStringExtra("TAG_DOCTOR");
        hospital_id=getIntent().getStringExtra("TAG_HOSPITAL_ID");


        productsList = new ArrayList<HashMap<String, String>>();

        // Loading products in Background Thread
        new LoadAllProducts().execute();


        TextView title = (TextView) findViewById(R.id.title);
        title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));

        RelativeLayout previous = (RelativeLayout) findViewById(R.id.previous);

        previous.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setPreviousMonth();
                refreshCalendar();
            }
        });

        RelativeLayout next = (RelativeLayout) findViewById(R.id.next);
        next.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setNextMonth();
                refreshCalendar();

            }
        });

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                                    int position, long id) {

                ((CalendarAdapter) parent.getAdapter()).setSelected(v);
                String selectedGridDate = CalendarAdapter.dayString
                        .get(position);
                String[] separatedTime = selectedGridDate.split("-");
                String gridvalueString = separatedTime[2].replaceFirst("^0*",
                        "");// taking last part of date. ie; 2 from 2012-12-02.
                int gridvalue = Integer.parseInt(gridvalueString);
                // navigate to next or previous month on clicking offdays.
                if ((gridvalue > 10) && (position < 8)) {
                    setPreviousMonth();
                    refreshCalendar();
                } else if ((gridvalue < 7) && (position > 28)) {
                    setNextMonth();
                    refreshCalendar();
                }
                ((CalendarAdapter) parent.getAdapter()).setSelected(v);
                pDialog.dismiss();
                if(items2.contains(selectedGridDate)) {
                    Intent i = new Intent(getApplicationContext(),
                            requestconfirmation.class);
                    // Closing all previous activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.putExtra("date",date);
                    i.putExtra("da_id",TAG_DA_ID);
                    i.putExtra("status",status);
                    i.putExtra("time_interval",time_interval);
                    i.putExtra("appointment_type",appointment_type);
                    i.putExtra("no_of_patient",no_of_patient);
                    i.putExtra("doctor_name",doctor_name);
                    i.putExtra("specialty",specialty);
                    i.putExtra("hospital_name",hospital_name);
                    i.putExtra("start_time",start_time);
                    i.putExtra("end_time",end_time);

                    startActivity(i);
                }
                else {
                    showToast("No Appointment is set in this date.");
                }
            }
        });
    }

    protected void setNextMonth() {
        if (month.get(GregorianCalendar.MONTH) == month
                .getActualMaximum(GregorianCalendar.MONTH)) {
            month.set((month.get(GregorianCalendar.YEAR) + 1),
                    month.getActualMinimum(GregorianCalendar.MONTH), 1);
        } else {
            month.set(GregorianCalendar.MONTH,
                    month.get(GregorianCalendar.MONTH) + 1);
        }

    }

    protected void setPreviousMonth() {
        if (month.get(GregorianCalendar.MONTH) == month
                .getActualMinimum(GregorianCalendar.MONTH)) {
            month.set((month.get(GregorianCalendar.YEAR) - 1),
                    month.getActualMaximum(GregorianCalendar.MONTH), 1);
        } else {
            month.set(GregorianCalendar.MONTH,
                    month.get(GregorianCalendar.MONTH) - 1);
        }

    }

    protected void showToast(String string) {
        Toast.makeText(this, string, Toast.LENGTH_SHORT).show();

    }

    public void refreshCalendar() {
        TextView title = (TextView) findViewById(R.id.title);

        adapter.refreshDays();
        adapter.notifyDataSetChanged();
        handler.post(calendarUpdater); // generate some calendar items

        title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));
    }

    public Runnable calendarUpdater = new Runnable() {

        @Override
        public void run() {
            items.clear();

            // Print dates of the current week
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
            String itemvalue;
            for (int i = 0; i < 7; i++) {
                itemvalue = df.format(itemmonth.getTime());
                itemmonth.add(GregorianCalendar.DATE, 1);

            }

            adapter.setItems(items);
            adapter.notifyDataSetChanged();
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received
            // means user edited/deleted product
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }

    /**
     * Background Async Task to Load all product by making HTTP Request
     * */
    class LoadAllProducts extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(CalendarView.this);
            pDialog.setMessage("Loading Appointments. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * getting All products from url
         * */
        protected String doInBackground(String... args) {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("doctor_id", doctor_id));
            params.add(new BasicNameValuePair("hospital_id", hospital_id));
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_get_appointment, "POST", params);

            // Check your log cat for JSON reponse
            Log.d("All Appointments: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // products found
                    // Getting Array of Products
                    products = json.getJSONArray(TAG_APPOINTMENTS);
                    items2.clear();
                    // looping through All Products
                    for (int i = 0; i < products.length(); i++) {
                        JSONObject c = products.getJSONObject(i);

                        // Storing each json item in variable
                        date = c.getString(TAG_DATE);
                        da_id = c.getString(TAG_DA_ID);
                        status = c.getString(TAG_STATUS);
                        time_interval=c.getString(TAG_TIME_INTERVAL);
                        appointment_type=c.getString(TAG_APPOINTMENT_TYPE);
                        no_of_patient=c.getString(TAG_NO_OF_PATIENT);
                        doctor_name=c.getString(TAG_DOCTOR_NAME);
                        specialty=c.getString(TAG_SPECIALTY);
                        hospital_name=c.getString(TAG_HOSPITAL_NAME);
                        temp_start = c.getString(TAG_START_TIME);
                        temp_end = c.getString(TAG_END_TIME);
                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_DATE, date);
                        map.put(TAG_DA_ID, da_id);
                        map.put(TAG_STATUS, status);

                        start_time.add(temp_start);
                        end_time.add(temp_end);
                        items2.add(date);

                        // adding HashList to ArrayList
                        productsList.add(map);
                    }

                } else {
                    // no products found
                    // Launch Add New product Activity

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    items.clear();

                    // Print dates of the current week
                    DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
                    String itemvalue;
                    for (int i = 0; i < 7; i++) {
                        itemvalue = df.format(itemmonth.getTime());
                        itemmonth.add(GregorianCalendar.DATE, 1);

                    }

                    adapter.setItems(items2);
                    adapter.notifyDataSetChanged();

                }
            });

        }

    }
}

这里是错误

10-30 02:47:02.699 2195-2195/com。srg。ibc。任命申请书W/EGL_genymotion﹕ 未实施eglSurfaceAttrib 10-30 02:47:03.075 2195-2195/com。srg。ibc。任命应用程序E/WindowManager﹕ 活动网。srg。ibc。任命申请。CalendarView已泄漏Windows com.Android内部的政策impl。电话窗口$DecorView@53698880这是最初添加到这里的android。看法windowsleed:activitycom。srg。ibc。任命申请。CalendarView已泄漏Windows com.Android内部的政策impl。电话窗口$DecorView@53698880这最初是在android上添加的。看法ViewRootImpl。(ViewRootImpl.java:374)在android上。看法WindowManagerImpl。android上的addView(WindowManagerImpl.java:292)。看法WindowManagerImpl。android上的addView(WindowManagerImpl.java:224)。看法WindowManagerImpl$CompatModeWrapper。android上的addView(WindowManagerImpl.java:149)。看法Window$LocalWindowManager。android上的addView(Window.java:547)。应用程序。对话在com上显示(Dialog.java:277)。srg。ibc。任命申请。CalendarView$LoadAllProducts。android上的onPreExecute(CalendarView.java:264)。操作系统。异步任务。android上的executeOnExecutor(AsyncTask.java:586)。操作系统。异步任务。在com上执行(AsyncTask.java:534)。srg。ibc。任命申请。日历视图。android上的onCreate(CalendarView.java:100)。应用程序。活动在android上执行创建(Activity.java:5008)。应用程序。仪器仪表。android上的callActivityOnCreate(Instrumentation.java:1079)。应用程序。活动线程。android上的performLaunchActivity(ActivityThread.java:2023)。应用程序。活动线程。android上的handleLaunchActivity(ActivityThread.java:2084)。应用程序。活动线程。在android上访问$600(ActivityThread.java:130)。应用程序。android上的ActivityThread$H.handleMessage(ActivityThread.java:1195)。操作系统。处理程序。android上的dispatchMessage(Handler.java:99)。操作系统。活套。android上的loop(Looper.java:137)。应用程序。活动线程。java上的main(ActivityThread.java:4745)。朗。反思。方法java上的invokenactive(本机方法)。朗。反思。方法在com上调用(Method.java:511)。Android内部的操作系统。ZygoteInit$MethodandArgscaler。在com上运行(ZygoteInit.java:786)。Android内部的操作系统。合子体。dalvik的main(ZygoteInit.java:553)。系统原生艺术。主(本机方法)

希望你们能帮我伙计们。提前谢谢。

共有2个答案

仇正平
2023-03-14

您试图在退出活动后显示一个对话框。

桓兴腾
2023-03-14

您的代码可能会试图删除进度对话框pDialog.dismiss();后,调用完成()

您只需在解雇程序周围放置try-catch块即可。

 类似资料:
  • 下面是问题的链接:SPOJ-ACTIV 我想出了这个问题的重现如下: 其中next()查找具有开始时间的活动的索引 这是我的java解决方案,虽然它通过了SPOJ工具包的许多测试用例,但是它确实为一些提供了WA。我的概念/解决方案有什么问题?

  • 就在我解决了我的第一个问题之后,这个问题出现了:(请帮我解决它... 03-02 12:47:02.785 9439-9439/com . ucu . CCS . class record E/window manager£Android . view . window leaved:Activity com . ucu . CCS . class record . log in已泄漏window

  • 我在android studio中创建了一个新的项目,当我试图运行它时,它显示缺省活动找不到。我检查了我的清单文件,这不包含任何问题。运行时有红色X标记android studio应用

  • 本文向大家介绍解决Tensorflow 内存泄露问题,包括了解决Tensorflow 内存泄露问题的使用技巧和注意事项,需要的朋友参考一下 使用tensorflow进行编程时,经常遇到操作不当,带来的内存泄露问题,这里有一个可以帮助debug问题所在方法: https://stackoverflow.com/questions/51175837/tensorflow-runs-out-of-mem

  • 本文向大家介绍Python跑循环时内存泄露的解决方法,包括了Python跑循环时内存泄露的解决方法的使用技巧和注意事项,需要的朋友参考一下 Python跑循环时内存泄露 今天在用Tensorflow跑回归做测试时,仅仅需要循环四千多次 (补充说一句,我在个人PC上跑的)。运行以后,我就吃饭去了。等我回来后,Console窗口直接亮红了!!! 此处忘了截图 ,反正就是说Keras出现了什么什么错误。

  • 本文向大家介绍PyCharm 解决找不到新打开项目的窗口问题,包括了PyCharm 解决找不到新打开项目的窗口问题的使用技巧和注意事项,需要的朋友参考一下 在使用PyCharm或其他JetBrains系IDE过程中,偶尔会出现在新窗口打开一个新项目后,找不到新打开的窗口的情况。 尤其在使用双显示器情况下,出现的次数比较多。 但鼠标放任务栏ide图标上,还会出现预览窗口,如下图所示: 这是什么情况呢