I have a GCM class, which gets a message that has 2 separate strings from Google GCM server. I need to use those 2 strings inside another activity of my application. The problem is that i do not know in advance how many these gcm messages are gonna be. I need to store these values and use them in another Activity to present them to the user inside a layout. I’ m finding this difficult cause first of all, i don’t know how many these messages are gonna be, so i can’t draw the layout in advance, and secondly cause i haven’t found an effective of storing these 2 strings together, so that i am able later to manipulate them.
Each group of these two strings, belong to a user and should be stored in a way so that they can be retrieved separately from other group of strings.
I have tried to do this by using SharePrefrences or intents but i can’t find a proper solution to this.
I know my question might seem silly, and i am not asking for a solution, but i am stuck and i would be really glad, if someone could give me some advice or guidance on some workaround to this, or where to look..
You should be able to store them in an
ArrayListorHashMapand send them through anIntent. You won’t need to know how many there are, just use a loop to add however many exist into the list. When showing them, you can use aListViewto show them so you don’t have to worry about knowing how many there are each time but you can get the count so you can know if needed. Other than that, its hard to say without seeing what you have tried, what is/isn’t working/ or what you already know so I have added a few links which may be helpful in understanding these objectsArrayList
HashMap
consider LinkedHashMap if you are concerned with the order of the data.