1.出现fragment后台栈的bug。html
bug描述:当点击加入后台栈的操做按钮改变指定控件的内容以后,称为A操做;接下来又点击其它没有操做后台栈的按钮来修改原来指定的控件内容,称为B操做。而后点击back键,就会出现A操做以前的界面与B操做叠加的bug。android
由于咱们程序中改变的指定控件是FrameLayout,编程
<FrameLayout | |
android:id="@+id/frame_content" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_above="@+id/frameMenu" | |
android:layout_below="@+id/main_title" > | |
</FrameLayout> |
由于点击back键是回到了A操做以前的界面,而点击back键并不影响B操做显示的界面,FrameLayout会叠加,因此就会出现叠加的状况。数组
解决方法,当进行B操做的时候改变指定控件的内容时,清空后台栈。测试
清空方法:popBackStackImmediate()this
参考:http://www.cnblogs.com/qixing/p/4015262.htmlspa
这个方法:if (getSupportFragmentManager().getFragments() != null
&& getSupportFragmentManager().getFragments().size() > 0) {
getSupportFragmentManager().getFragments().clear();code
会出现数组越界的bug。htm
我所用的方法,经测试没有问题:对象
// 清除后台栈by Hanshenquan
private void clearBackStack() {
if (getSupportFragmentManager().getFragments() != null
&& getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStackImmediate(null,
FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
}
getBackStackEntryCount()是得到后台栈中的数量。
测试,显示back栈中对象的数量:
int num = getSupportFragmentManager().getBackStackEntryCount();
Toast.makeText(this, "Fragment数量 "+String.valueOf(num), Toast.LENGTH_LONG).show();
2.手机线链接很差,会出一些问题,因此在没有其它错误,且重启编程软件无效以后,应该考虑从新插拔链接手机的数据线,确保链接操做没有问题。
3.获取类的对象3种方式。Class.forName(),类名.class和对象.getClass。