我正在使用 Android Studio 3.0.1,它允许检查 onSaveInstanceState
中的 Bundle
对象:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
为此添加一个断点,一旦调试器停止,请右键单击 Bundle
对象,如屏幕截图所示,然后从上下文菜单中选择“Show Bundle Objects...”。
然后会打开一个窗口,列出 Bundle
对象,如以下屏幕截图所示:
有没有办法找出多少内存整个Bundle
及其子项占用?我想确定更大的 block 以进行优化并避免在 Android >= 7 上抛出 TransactionTooLargeException
。
像 Ubuntu Disk Usage Analyzer 之类的东西会有帮助 - 请看截图:
最佳答案
你也可以使用这个:-
=> 在这里传递 Bundle
public int getBundleSizeInBytes(Bundle bundle ) {
Parcel parcel = Parcel.obtain();
parcel.writeValue(bundle);
byte[] bytes = parcel.marshall();
parcel.recycle();
return bytes.length;
}
然后使用android.text.format.Formatter.formatFileSize(activityContext, bytes)
来漂亮的输出。
关于android - 如何在 onSaveInstanceState 中查看 Bundle 对象的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47633002/