如何在Android中存储和调用浮点数组?

时间:2016-10-09 04:37:41

标签: java android arrays save

我有一个数组`mydata' 3个数字。

10 9 8 7 6 5 4 3 2 1 =试验次数

private void button5_Click(object sender, EventArgs e) { MessageBox.Show( "In order to bet 'High' press the 'ALT' Key and the 'H' key at the same time.\n" + "In order to bet 'Low' press the 'ALT' Key and the 'L' key at the same time.\n" + "In order to reduce the bet's value in half press the 'ALT' Key and the 'H' key at the same time."); } =成功次数

class Program { static int[] CreateArray() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; return array; } //I changed this to receive an input array static void PrintNumbers( int[] inputArray) { foreach (int numbers in inputArray) { Console.WriteLine(numbers); } } //this function should reverse any array passed to it static void ReverseArray(int[] inputArray) { int len = inputArray.Length; int[] newArray = new int[len]; foreach (int i in inputArray) { newArray[i] = inputArray[len - 1]; len--; } } static void Main(string[] args) { int[] numbers = CreateArray(); PrintNumbers(numbers); ReverseArray(numbers); //Console.ReadLine(); } } =(x / y)* 100

但是当我退出我的应用程序时,这些数据就会被删除,而且我的所有号码都已消失。

如何在重新启动应用程序时将此信息保存在文件中并重新调用,以便数据始终保持原样?

3 个答案:

答案 0 :(得分:2)

SharedPreferences关闭时存储您的数组数据。在记录备份/打开时,您可以从SharedPreference获取数据,它将在那里。

SharedPreferences tutorial

希望它有所帮助。干杯!

答案 1 :(得分:2)

你的变量将被删除,因为每当你的应用程序被杀死时,它的所有数据都会从RAM中擦除。你需要使用'sharedPreferences'来存储这样的小数据。 见下面的链接:

How to use SharedPreferences in Android to store, fetch and edit values

答案 2 :(得分:0)

阅读Storage Options,了解有关为您的应用永久存储数据的信息。

相关问题