0

First of all, sorry for newbie questions..

In my app I have two activities.

Activity A is in general a registration form with edittexts, autocompletetextviews, spinners and two buttons X and Y which leads to Activity B , practically a map activity. Applying startActivityForResult for button X I go to Activity B taking some data, then back to A ( onActivityResult ) then button Y leads with same procedure to Activity B and finally back to A.

The problems is that Activity A doesn't remember results from button X procedure when button Y ends its own.

Question1. Filling edittexts in activity A, going to activity B and back to A doesn't prevent activity A to hold this kind of data contrary to startActivityForResult and onActivityResult . Why is that;

Question 2: What is the proper way to save data from button X in activity A so that activity holds results both from the two button procedure when button Y finishes its own;

Thanks in advance..

Rushabh Patel
  • 3,052
  • 4
  • 26
  • 58

3 Answers3

0

The proper way to send simple data between activies is using extras. Have a look at Android official documentation

FKSI
  • 148
  • 5
0

@FKSI is correct that the proper way to do this is using Intents Extras. However, I use Several Fragments inside each activity and when I have a mix of many activities and fragments all playing together AND if the data is not a lot, I find it very easy to use a SharedPreferences. Using getApplicationContext() as the Context, saving any SharedPreferences is accessible from anywhere in the package of the app.

user1406716
  • 9,565
  • 22
  • 96
  • 151
-1

If I dont misunderstand, you just want to save temp data. I recommend you to use Application class. An example can be found here: Example. Hope it helps.

Kingfisher Phuoc
  • 8,052
  • 9
  • 46
  • 86
  • As the link may get broken in future, you should include an example in your answer. Also, your answer suggests a bad practice, as counter-argued [here](http://stackoverflow.com/questions/19158339/python-why-are-global-variables-evil) – Marius Aug 04 '14 at 08:44
  • @Marius: this is subject to discussion. so just claiming that global variables are bad practice it is not enough. there are arguments for it and against it, practically as anything else. i personally find them useful in certain cases specifically from performance perspective. however, i agree that for this particular case not useful – eldjon Aug 04 '14 at 08:56
  • You answer a question and disagree with your own answer. – Marius Aug 04 '14 at 09:01
  • i did not answer any question. – eldjon Aug 04 '14 at 09:07
  • @Marius: 1st: Link is not broken yet, I checked it (It's just discussion, why need code?). 2nd: I dont think save everything to db is better idea. with some small things, it's not neccessary, that's why Application class exists. – Kingfisher Phuoc Aug 04 '14 at 09:09
  • Can anyone answer to question 1; I want to understand the logic behind that – user3649152 Aug 04 '14 at 11:57