我得到了
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
在我的代码中,我搜索了statckoverflow,我得到了以下代码作为解决方案。
现在我没有得到IllegalStateException,但问题是..代码正在清除整个堆栈跟踪。但我想只弹出Backstack中的最后一个事务/条目。该怎么做??
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStack(getSupportFragmentManager().getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
如何仅弹出Backstack中的最后一个事务/条目?
我如何添加到堆栈的代码:
fragmentManager.beginTransaction().
setCustomAnimations(R.anim.slide_in_left, R.anim.slide_in_left, R.anim.slide_out_right, R.anim.slide_out_right).
replace(R.id.content_frame, pageFragment, currentItem).
addToBackStack(currentItem).
commit();
答案 0 :(得分:1)
弹出最后一个交易条目:
int last = getActivity().getSupportFragmentManager().getBackStackEntryCount() - 1
FragmentManager.BackStackEntry entry = getSupportFragmentManager().getBackStackEntryAt(last);
String tag = entry.getName();
Fragment fragment = getSupportFragmentManager().findFragmentByTag("last"); //get the last fragment
同样在交易期间,您必须添加标签..
fragmentTransaction.addToBackStack("last");
您还可以使用popBackStackImmediate弹出最后一个片段:
getSupportFragmentManager().popBackStackImmediate(getSupportFragmentManager().getBackStackEntryAt(last), FragmentManager.POP_BACK_STACK_INCLUSIVE);
使用标签使用从BackStack弹出片段:
getSupportFragmentManager().popBackStack ("last", FragmentManager.POP_BACK_STACK_INCLUSIVE);
答案 1 :(得分:1)
对于此错误:
java.lang.IllegalStateException:之后无法执行此操作 的onSaveInstanceState
而不是<div id="pdf_area">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<div><img src="example.png" /></div>
<div>
<p><font size="3" color="red">print this to pdf</font></p>
</div>
</div>
<div id="chart">
<canvas style="position: absolute; top: 0px; left: 0px; width: 1117px; height: 350px;" width="1117" height="350"></canvas>
</div>
<a href="#" onclick="downloadPDF('html')" >Download PDF</a>
<script>
function downloadPDF(shouldDownload) {
var funcStr = window.location.hash.replace(/#/g, '') || 'auto';
var doc = examples[funcStr]();
doc.setProperties({
title: 'Example: ' + funcStr,
subject: 'A jspdf-autotable example pdf (' + funcStr + ')'
});
if (shouldDownload) {
doc.save('table.pdf');
} else {
document.getElementById("output").src = doc.output('datauristring');
}
}
</script>
,请使用commit()
,问题就会消失。然后使用您想要的方法。