2

I want to transfer between activities the data that i edit in my EditText fields. If i transfer from activity 1 to activity 2 i want to be able in activity 2 to edit the data that i received from activity 1, to save the new data in the activity 2 and transfer to the activity 3. How can i save and transfer the data in the same time. Now with shared preferences i can tranfer but i can't save the data that i just edit in the current activity. Please Help! Thank you!

this is the code used to save the weight in Activity 1 (WEEK1):

SharedPreferences WeightPreferences = getSharedPreferences("WEEK1", MODE_PRIVATE);
String r1 = w1.getText().toString();
String r2 = w2.getText().toString();
String r3 = w3.getText().toString();
String r4 = w4.getText().toString();
String r5 = w5.getText().toString();
SharedPreferences.Editor editor = WeightPreferences.edit();
editor.putString("wr1", r1);
editor.putString("wr2", r2);
editor.putString("wr3", r3);
editor.putString("wr4", r4);
editor.putString("wr5", r5);
editor.commit();

This is the code used to show the weights from Activity 1 in Activity 2 (WEEK2) and so on:

SharedPreferences WeightPreferences = getSharedPreferences("WEEK1", MODE_PRIVATE);
String string1 = weightPreferences.getString("wr1", null);
String string2 = weightPreferences.getString("wr2", null);
String string3 = weightPreferences.getString("wr3", null);
String string4 = weightPreferences.getString("wr4", null);
String string5 = weightPreferences.getString("wr5", null);
w1.setText(string1);
w2.setText(string2);
w3.setText(string3);
w4.setText(string4);
w5.setText(string5);
george
  • 23
  • 4
  • http://stackoverflow.com/questions/15859445/how-do-you-pass-a-string-from-one-activity-to-another/15859488#15859488. – Raghunandan Apr 08 '13 at 16:37

2 Answers2

0

You can create a arraylist with all your data and transfer the object to the calling event using

intent.putExtra("Name", Object_with_all_your_content);

Did I understand your question?

Pang
  • 9,564
  • 146
  • 81
  • 122
Joseph Selvaraj
  • 2,225
  • 1
  • 21
  • 21
  • hi! thank you for you answer. i have a bug now. so i have MainActivity wich is my Home Activity from where i can acces Activity1 and Activity2. I use your method to transfer the numbers from Activity1 to Activity2 and everything is working fine. But when i hit home button and go to MainActivity, if i try to open from here Activity2, is crashing.. I don't understand why.. – george Apr 10 '13 at 12:57
  • can you share the logcat error/exception message. You can see the details in the exception. – Joseph Selvaraj Apr 10 '13 at 16:55
0

Put the values into an array and send it like this :

To send :

Intent intent =new Intent(ccurrentClass.this, anotherClass.class);
Bundle b = new Bundle();
b.putSerializable("value", arrayOfString);
intent.putExtras(b);
startActivity(intent);

TO retrieve :

Intent intent = getIntent();
Bundle b = intent.getExtras();
String[][] data = (String[][]) b.getSerializable("value");
Kaidul
  • 15,409
  • 15
  • 81
  • 150
  • ok but i want to be able to edit the numbers that i receive, to save them in the current activity and transfer further. then edit again the numbers, save in the current activity and transfer to the next and so on. this solution will help me? thank you – george Apr 09 '13 at 09:42
  • The values are in the `String[][]` and you can modify it in any way as you wish and then again send them by the above way so many times from activity to activity as you wish. By the way, if this answer helps you, accept and upvote it – Kaidul Apr 09 '13 at 10:43
  • yes it helped me to find the solution. how can i upvote u? thanks – george Apr 10 '13 at 12:07
  • i have a bug now. so i have MainActivitywich is my Home Activity from where i can acces Activity1 and Activity2. I use your method to transfer the numbers from Activity1 to Activity2 and everything is working fine. But when i hit home button and go to MainActivity, if i try to open from here Activity2, is crashing.. I don't understand why.. – george Apr 10 '13 at 12:55
  • There is a up-down button above here...beside my answer, and below that button there is *correct-mark* button. Please click it and accept my answer. Please post a new question with the code you have tried so that we can help you about your new bug – Kaidul Apr 10 '13 at 17:04