如何检查onSaveInstanceState中Bundle对象的大小? [英] How to examine the size of the Bundle object in onSaveInstanceState?

查看:117
本文介绍了如何检查onSaveInstanceState中Bundle对象的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio 3.0.1,该软件允许检查 onSaveInstanceState 中的 Bundle 对象:

I am using Android Studio 3.0.1 which allows to inspect the Bundle object in onSaveInstanceState:

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}

为此添加一个断点,一旦调试器停止,请右键单击 Bundle 对象,如屏幕快照所示,然后从上下文菜单中选择 Show Bundle Objects ...。

To do so add a breakpoint and once the debugger stops right click the Bundle object as shown in the screenshot and select "Show Bundle Objects..." from the context menu.

然后打开一个窗口,将捆绑对象列出为在此屏幕快照中显示:

Then a window opens to list the Bundle objects as shown in this screenshot:

一种找出全部捆绑包有多少内存以及孩子所占的方式?我想确定更大的块以进行优化,并避免在Android> = 7上抛出 TransactionTooLargeException

Is there a way to find out how much memory the whole Bundle and it's children occupy? I want to identify the bigger chunks to optimize and avoid TransactionTooLargeException to be thrown on Android >= 7.

像Ubuntu 磁盘使用情况分析器这样会有所帮助-请参见screeshot:

Something like Ubuntu Disk Usage Analyzer would be helpful - see screeshot:

推荐答案

您也可以使用此方法:-

You can also use this one :-

=>只需在此处传递捆绑包

=> just pass the Bundle here

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)可以很好地输出。

Then use android.text.format.Formatter.formatFileSize(activityContext, bytes) to output nicely.

这篇关于如何检查onSaveInstanceState中Bundle对象的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆