1、 错误 :Can not perform this action after onSaveInstanceState 场景:应用中使用FragmentDialog统一管理弹出框,分别在基类BaseActivity和BaseFragment中增加显示和隐藏方法(show 和dismiss)。在某些网络异步请求中,在请求开始时调用show()方法显示弹出框,再请求结束时调用dissmiss隐藏弹出框。 错误日志:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at com.yunyue.weishangmother.activity.BaseFragmentActivity.showProgressDialog(BaseFragmentActivity.java:47) at com.yunyue.weishangmother.activity.LoginActivity$1.onPrepare(LoginActivity.java:98) at com.yunyue.weishangmother.dao.BaseDao.doAction(BaseDao.java:45) at com.yunyue.weishangmother.dao.AccountMangeDao.login(AccountMangeDao.java:35) java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at com.yunyue.weishangmother.activity.BaseFragmentActivity.dismissProgressDilag(BaseFragmentActivity.java:63) at com.yunyue.weishangmother.activity.GoodsListActivity$5.onFinish(GoodsListActivity.java:209) at com.yunyue.weishangmother.dao.BaseDao$1.onFinish(BaseDao.java:108) java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at com.yunyue.weishangmother.activity.BaseFragmentActivity.dismissProgressDilag(BaseFragmentActivity.java:64) at com.yunyue.weishangmother.fragment.BaseFragment.dissmissProgressDialog(BaseFragment.java:119) at com.yunyue.weishangmother.fragment.HomeFragment$1.onFinish(HomeFragment.java:151) at com.yunyue.weishangmother.dao.BaseDao$1.onFinish(BaseDao.java:107)
问题分析: 情况一:在一个程序中使用fragment+异步更新界面,今天出现发现异常,记录解决办法。 异常:java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState; 分析:仔细查看后发现,是由于异步线程结束后,要弹出对话框提示,但是这时候fragment已经进入后台,所以抛出这个异常; 解决办法:在线程运行结束后,需要弹出对话框的时候,先做一个判断isResumed()。 google给的文档中是这样说的: public final boolean isResumed () Return true if the fragment is in the resumed state. This is true for the duration of onResume() and onPause() as well. 翻译:当fragment在resumed状态时返回true,即fragment在生命周期的onResume()和onPause()之间时返回true。 情况二:在Activity中dismissDiaog时,提示上述错误。 解决方法: DialogFragment本身提供了两个方法: void dismiss() 说明:Dismiss the fragment and its dialog. void
dismissAllowingStateLoss() 说明:Version of dismiss() that uses FragmentTransaction.commitAllowingStateLoss(). 使用dismissAllowingStateLoss可以忽略状态。但是对于show()方法提供的两个方法,内部都是用了commit()提交,而不能使用commitAllowingStateLoss()。 参考:把commit()方法替换成 commitAllowingStateLoss()就行 http://blog.sina.com.cn/s/blog_5da93c8f0101rgb2.html
情况三:针对Activity中showDialog()时显示上述问题,参考情况一,增加一个标志位isResume来控制。
2、Could not read input channel file descriptors from parcel. 错误日志: java.lang.RuntimeException: Could not read input channel file descriptors from parcel. at android.view.InputChannel.nativeReadFromParcel(Native Method) at android.view.InputChannel.readFromParcel(InputChannel.java:148) at android.view.InputChannel$1.createFromParcel(InputChannel.java:39) at android.view.InputChannel$1.createFromParcel(InputChannel.java:36)
网上给出的说法: (1)RemoteView中添加的图片太大了,超过40K会报这个异常 (2)Intent传递的数据太大了超过1M也会报这个错误 (3)FileDescripter太多而且没有关闭,looper太多没有quit。 (4)试试在AndroidManefest.xml中对当前Activity配置configchange=“orientation|keyboardHidden”强制在Activity横竖屏切换的时候不重新onCreate。
3、android.os.TransactionTooLargeException(分享图片太大) android.os.TransactionTooLargeException at android.os.BinderProxy.transact(Native Method) at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:683) at android.view.ViewRootImpl.setView(ViewRootImpl.java:525) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:260) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.widget.Popupwindows.invokePopup(PopupWindow.java:1019) at android.widget.PopupWindow.showAtLocation(PopupWindow.java:850) at android.widget.PopupWindow.showAtLocation(PopupWindow.java:814) at com.yunyue.weishangmother.util.UMengSDK.shareWithCustomPanel(UMengSDK.java:97) 通过代码分析是在调用友盟分享时出现错误。具体在shareWithCustomPanel方法中建立分享内容(包括标题、内容、图片链接),其中 public void setShareContent(String title, String content, String imagePath, String url, String id, String type) { this.title = title; this.content = content; this.id = id; this.type = type; if (!TextUtils.isEmpty(imagePath)) { urlImage = new UMImage(mActivity, imagePath);
} else {
urlImage = new UMImage(mActivity, R.drawable.ic_launcher); } urlImage.setTargetUrl(url); this.url = url; } 分析可能是传入的图片链接中图片过大,导致上述问题。
4、java.lang.IllegalStateException: eglMakeCurrent failed EGL_BAD_ALLOC at android.view.HardwareRenderer$GlRenderer.createSurface(HardwareRenderer.java:1123) at android.view.HardwareRenderer$GlRenderer.createEglSurface(HardwareRenderer.java:1010) at android.view.HardwareRenderer$GlRenderer.initialize(HardwareRenderer.java:833) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1845) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1261)
5、java.lang.IllegalArgumentException: Receiver not registered: android.widget.ZoomButtonsController$1@3bdd2de8 at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:871) at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:2110) at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:529) 解决:发现是webview的 ZoomButton,也就是那两个放大和缩小的按钮,导致的。如果设置为让他们出现,并且可以自动隐藏,那么,由于他们的自动隐藏是一个渐变的过程,所以在逐渐消失的过程中如果调用了父容器的destroy方法,就会导致Leaked。 所以解决方案是,在destroy之前,先让他俩立马消失。 我的解决办法是,在finish掉此activity时,把子view 全部remove掉。理论上说,只需要remove这个zoom view就可以,但是我没找到获取该view的办法,只好remove掉所有的子view。这样在activity destroy时就不会报 WindowLeaked的错误了。 @Override public void finish() { ViewGroup view = (ViewGroup) getWindow().getDecorView(); view.removeAllViews();
super.finish(); } 也有人说,可以直接设置webView.setVisiable(View.GONE); 在Activity的onDestroy里面加上这么一句:web.setVisibility(View.GONE);把WebView设置为GONE就可以了。