Answer the question
In order to leave comments, you need to log in
Transferring data between activities.?
How to transfer data between activities?
how to use this data in 2 activities?
and how to do so that each new data would create a string for itself and throw it there?
Answer the question
In order to leave comments, you need to log in
Before calling startActivity, pass data to Intent.
For example:
String data = "Эти данные необходимо передать";
Intent i = new Intent(MainActivity.this, SecondActitviy.class);
i.putExtra("testNameData", data);
startActivity(i);
When switching between Activities, Intent is used, it has a setData method (and, it seems, getData), through them they put / take data. Google, and you will find not only the code, but also tutorials, it seems that Klimov had one.
Seems like this:
In AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/emblem"
android:label="@string/app_name" android:name="AppEngine">
...
</application>
public class AppEngine extends Application {
@Override
public void onCreate(){
super.onCreate();
}
}
To transfer data from an array, for example, you can do this:
Intent NewActivityIntent;
NewActivityIntent = new Intent(MainActivity.this, NewActivity.class);
int items_count = 0;
for (int i = 0; i < item_List.size(); i++) {
String item_name = "item_" + items_count;
NewActivityIntent.putExtra(item_name, "Данные из массива под номером " + i);
items_count++;
}
NewActivityIntent.putExtra("items_count", items_count);
Bundle extras = getIntent().getExtras();
int items_count = extras.getInt("items_count");
for (int i = 0; i < items_count; i++) {
String string = "item_" + i;
String string_item = extras.getStringArray(string);
item_List.add(string_item );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question