我有一个控制多个片段的活动。默认片段是HomepageFragment. 当替换到不同的 Fragment 时,我总是确保堆栈保持平坦 - 这意味着只有HomepageFragment保持在堆栈中并在其顶部是当前 Fragment。例如:
HomepageFragmentFragmentA需要替换 to - 一切都是好的原因HomepageFragment是最后一个 FragmentHomepageFragment->FragmentA FragmentB需要替换为- 首先弹出堆栈上的最后一个 Fragment ( fragmentA) 然后替换为FragmentBHomepageFragment->FragmentB在生产中,我看到很多TransactionTooLargeException崩溃。
我曾经TooLargeTool跟踪问题的来源,我发现当我在活动中的片段之间切换时,其中有一个android:support:fragments键SaveInstanceState变得越来越大(呈指数级),直到发生崩溃。
似乎即使从堆栈中弹出时,有关原始事务的一些数据也会继续保存。
按照此处的建议将其删除会导致 Activity 在被操作系统杀死后无法正确恢复。
我压平堆栈的方法有什么问题吗?有没有更好的方法?究竟保存在什么数据下android:support:fragments?
注意:我没有为这些片段设置任何参数。此外,它们在其 saveInstanceState 包中保存了非常小的数据。
谢谢!
android android-fragments android-activity onsaveinstancestate transactiontoolargeexception
尝试共享图像文件时,我不断收到此错误:
java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小1085992字节
我假设一个解决方案是将图像压缩得更多,这会减小尺寸.这是完成这项工作的功能:
public static File saveBitmaptoFile(Bitmap bitmap, File pictureFile) {
FileOutputStream out = null;
try {
out = new FileOutputStream(pictureFile);
// on the next line I'm trying compress the heck out of image.
bitmap.compress(Bitmap.CompressFormat.JPEG, 1, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return pictureFile;
}
Run Code Online (Sandbox Code Playgroud)
这是共享功能:
private void shareToInstagram() {
String type = "image/png";
Intent share = new Intent(Intent.ACTION_SEND); …Run Code Online (Sandbox Code Playgroud) android ×2