我有一个带有两个EditText字段的活动和" Add"按钮,像这样:
<EditText
android:id="@+id/key"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="Key"/>
<EditText
android:id="@+id/value"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:hint="Value"/>
<Button
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
在我的Activity类中,我声明了一个数组(其范围是活动的类)来存储键值对:
public class ExampleActivity extends AppCompatActivity {
List<Pair<String, String>> paramsArray = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
每次用户填写字段并单击按钮时,都会向数组中添加一个新条目。
我的问题是:
这个活动是否会被Android操作系统破坏(例如,因为另一个应用程序当前正在运行)并使用空数组重新创建?
一般来说如何在活动中存储这样的东西?
答案 0 :(得分:0)
数据仅存储在运行时。每当您重新启动应用程序时,阵列都将为空。
要永久存储数据,您可以使用数据库或Web服务器。
我没有得到你的第二个问题。