I have an activity with two EditText fields and "Add" button, something like this:
<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"/>
In my Activity class I declare an array (its scope is activity's class) to store key-value pairs:
public class ExampleActivity extends AppCompatActivity {
List<Pair<String, String>> paramsArray = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
Everytime a user fills the fields and clicks the button a new entry is added to the array.
My question is:
could this activity be destroyed by Android OS (for example, because another app is currently running) and recreated with an empty array?
And in general how to store things like that within activity?