Questions tagged [android-sparsearray]

SparseArray is Android-specific data structure that maps integers to Objects. This tag is to be used with Android tag.

SparseArray is Android-specific data structure that maps integers to Objects. It is intended to be more memory efficient than using HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping. This tag is to be used with tag.

11 questions
5
votes
1 answer

Android SparseArray value comparison

So I was writing some very simple code and found a very unexpected behavior. All List and Map implementations use the equals method of a node to compare them. So if you would've a list of strings, and you would try to acquire the index of a string…
Displee
  • 670
  • 8
  • 20
1
vote
1 answer

Android: HashMap vs WeakHashMap vs SparseArray in terms of garbage collection

In Java, a HashMap object that is specified as a key is not eligible for garbage collection. A WeakHashMap object that is specified as a key is still eligible for garbage collection My question is in Android, what is the behavior of SparseArray in…
Richard Hu
  • 811
  • 5
  • 18
1
vote
1 answer

How can I save a SparseArray in a Room database?

I'm trying to persist a SparseArray in a Room database and can not get it to compile. I keep getting the "Not sure how to convert a Cursor to this method's return type" error message along with "The query returns some columns [plannerLineData] which…
mtdavem
  • 441
  • 1
  • 7
  • 17
1
vote
1 answer

Strange behavior of JUnit4 with static final SparseArray field in Enum in android

I observed strange behavior of SparseArray defined as static final field of Enum while testing with JUnit4. Enum class: public enum ConstantType { PI(0, Math.PI), E(1, Math.E), ; private static final SparseArray
Yanny
  • 178
  • 12
0
votes
0 answers

Is it possible to add element to the front of a SparseArray?

I tried cloning a sparse array into a temp one and the clearing the original before adding the temp SparseArray back into the original one, but because the lookup is binary that doesn't seem to work. Is there any way to accomplish this or do I need…
nosh
  • 620
  • 3
  • 14
  • 50
0
votes
2 answers

How to substract single string from a sparseArray?

I've been working with Android Mobile Vision OCR API for a while. Everything is work perfectly until i found that i need to extract just single words from the whole SparseArray (Mobile Vision API default return is a TextBlocks which defined in a…
0
votes
1 answer

Android SparseBooleanArray ArrayIndexOutOfBounds

My app has an SparseBooleanArray to store selected entries in a ListAdapter. The array is initialized as empty in the constructor. private SparseBooleanArray mSelectedItemsIds; public TaskArrayAdapter(@NonNull Context context, @NonNull List
Felix
  • 95
  • 2
  • 11
0
votes
1 answer

Cannot resolve method for SparseArray

this is a piece of a script that has to recognize a text from the camera through TextRecognizer and then search a certain word inside the text. If the word is present, the system has to save in String found the word after. The problem is that I have…
user7867367
0
votes
0 answers

How to use a SparseArray as a data source for a spinner

I have a spinner that needs a data source. That data source has IDs that correspond with a unique ID in a database. I need my spinner to return the ID of the selected item as it appears in the data…
Elliot Huffman
  • 172
  • 3
  • 18
0
votes
1 answer

Passing the result from SparseArray to another activity

I am trying to scan a QR code and pass the value from the scanning result to another activity. I get the result in a SparseArray and extract the most latest scanned value. I am unable to retrieve any string in my second activity. Can anyone tel me…
SMG
  • 95
  • 1
  • 2
  • 11
0
votes
2 answers

SparseArray indexOfValue(Object) returns different result for equal variables

As you can see in the picture bellow latLng is equal to latlng1, but indexOfValue() returns different values. Why is that?
WantedLab
  • 11
  • 3