android.widget.PopupWindow$PopupDecorView leak when rotate device with menu open -
i started android development few weeks ago , went through creating menu in activity , read activity life cycle. kept running memory leak error when have pop menu open , rotate device.
i had problem on bigger project make simple recreating problem, 1 can follow steps:
i create application project in android studio, leave check phone , tablet minimum sdk api 16 -> choose basic activity template -> leave @ default (mainactivity , such ...)
without modifying code, ran on nexus 5 phone (android 6.0 installed on device) (screenshot)
click on setting menu (screenshot) rotate phone
- then see error appeared in android monitor window.
com.example.myapplication e/windowmanager: android.view.windowleaked: activity com.example.myapplication.mainactivity has leaked window android.widget.popupwindow$popupdecorview{36b6390 v.e...... ......id 0,0-588,144} added here ...
i know related activity went through onpause(), onstop() , ondestroyed() during device rotation process , popupwindow$popupdecorview did not closed. in sense similar question here [popupmenu popupwindow$popupviewcontainer leak] (popupmenu popupwindow$popupviewcontainer leak) can't figure out how solve since don't have reference menu in life cycle methods have dismissed.
my other question should android take care of automatically cause menu used? went through several tutorials on how create menu show how menu can created without mentioning above problem.
hope can give me lead solve annoying problem or @ least how close down pop menu in 1 of life cycle method.
mainactivity.java
package com.example.myapplication; import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.view; import android.view.menu; import android.view.menuitem; public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { snackbar.make(view, "replace own action", snackbar.length_long) .setaction("action", null).show(); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } @override protected void onpause() { super.onpause(); } } activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/apptheme.appbaroverlay"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="?attr/colorprimary" app:popuptheme="@style/apptheme.popupoverlay" /> </android.support.design.widget.appbarlayout> <include layout="@layout/content_main" /> <android.support.design.widget.floatingactionbutton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" app:srccompat="@android:drawable/ic_dialog_email" /> </android.support.design.widget.coordinatorlayout> menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.myapplication.mainactivity"> <item android:id="@+id/action_settings" android:orderincategory="100" android:title="@string/action_settings" app:showasaction="never" /> </menu>
add
android:configchanges="orientation|screensize"
in <activity> tag in manifest file error not occur. works me try , let me know.
Comments
Post a Comment