& ldquo; global & rdquo; array with different data types - Android


I'm new in programming for Android so maybe my question will be very easy to solve but still. I'm trying to make an array of different data types :

I have to add there :

   int number
   String name
   int number_2
   int time
   int total

And my question now is how to implement it in easiest way, and how to get data from it. In case that I have to get a different records for this variables and store it into list .
Also have a question about way how to keep all values which I handle inside of my array. I have to keep it because in my program I have to go back to other activities go forward to another and again collect data and add it to my array.

What will be the best and easiest solution ?

Thanks in advance for help

You could create the Array as an Array of Objects. All other classes are derived from Object, so you'll be able to store all types of objects in your Array. However, you would have to check the type of an object you get from the Array, before you'd be able to safely interpret as an object of a specific class. Moreover, you would have to use Integer instead of int.

If all (or at least multiple) of your elements you are intending to store in the Array are belonging to one (physical) entity, you could create a custom Class that holds its own properties as class members, and fill your Array with a list of instances of this Class.

Moreover, if you plan to add elements to your Array, you should use a List instead, e.g. an ArrayList.

As for retaining your data, you would have to either store it in a database, or save it to a file. In either way, you will have to save it upon close of the Activity, and load it again once the Activity starts