Joowon Ryoo Joowon Ryoo - 1 year ago 91
Java Question

Save memory and load quickly in android

'A' Object have very big boolean array.
'A[]' length is at least 150.

I want to save 'A[]' in device, and load quickly.
It should be load at least 1 second.
I have no idea how to do.

Using realm( can be possible?
Is there no way to save java instance and load?

Sorry for my poor english.

Answer Source

150 items of boolean are small amount of data for conventional mobile devices. You can save more than 1000 items at once within 1 second.

Method 1

Realm already supports byte[] as a datatype. You can use it by converting boolean array into byte array.

Method 2

As you know, boolean is just 1-bit(binary) data. There's lots of case to handle such bits, but for me, I love to handle it in naive manner.

  1. Let say you have 160 items of boolean.

    • true, false, ..., true, false
    • It can be converted to 1 or 0: 1010101....1010110
  2. 1 hex string contains 4 bits.

    • 1010 1110 0110 1100 can be expressed into AE6C
  3. Likewise, 160 bits can be converted into 160/4=40 strings.

  4. Just save 40 length strings to Realm or SharedPreference.

  5. Want to load? no problem. Convert 40 length strings into 160 length boolean array.

I think it could consume less than 100ms as those converting process is pretty fast in modern mobile CPUs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download