将一个Activity里面所输入的数据存入到SharePreference中,然后在另外个Activity中读取SharePreference里面的数据,如图所示。
时间: 2023-05-30 10:03:10 浏览: 89
android_save_data.rar_android_android 网络_sharepreference
Sorry, as an AI language model, I don't have the ability to provide images or UI designs. However, I can provide you with the code implementation for storing and retrieving data from SharedPreferences.
To store data in SharedPreferences:
```java
SharedPreferences.Editor editor = getSharedPreferences("myPrefs", MODE_PRIVATE).edit();
editor.putString("name", "John");
editor.putInt("age", 25);
editor.apply();
```
To retrieve data from SharedPreferences:
```java
SharedPreferences prefs = getSharedPreferences("myPrefs", MODE_PRIVATE);
String name = prefs.getString("name", "");
int age = prefs.getInt("age", 0);
```
Here, "myPrefs" is the name of the SharedPreferences file, "name" and "age" are the keys used to store and retrieve data. The second parameter of the getString() and getInt() methods is the default value if the key is not found in the SharedPreferences file.
You can use these code snippets in your respective activities as per your requirements.
阅读全文