0

I'm new to Android Studio, and I have a problem with my app.

I have two activities with some buttons that count click number and put the result on a text view. One of the buttons in the first activity start the second activity. In the second activity, I have to choose between 10 buttons which count click and set number in a text view, and after every click I have to return to the first activity. Then, the same process is repeated again.

I know how to change activity, but I don't know how to restore the first activity from the second, maintaining the text view value and the same when restore the second activity from the first.

How can I do it?

Pang
  • 9,564
  • 146
  • 81
  • 122

1 Answers1

0

how to restore the first activity from the second maintaining the textview value?

Do you mean by Store Certain Value into a Variable from First Activity so that the Value can be also use and retrieve by Second Activity or Other Activity?

If this is your Question, there are few Method to do so:

  1. This Method simply Throw Specify Value from one screen to another

How to pass a value from one Activity to another in Android?

  1. This Method store Specify Value into a Global Variable where all activity can be access and Store Permanently only until you command to delete. Something like a 'Session' of a Website.

Android Shared preferences example

In your case, I would use Method 2, to store the Value in Share Preference, and whenever I want to use any Specific Value from any Activity, I would just simple call the Share Preference out. Share Preference is very useful to store Value that used for Permanent usage of the application and its Scope is covering all the Activity in your Application. You can have Great Control of it, because you can specify to Store, Rewrite, Delete the value whenever you want, in wherever you want.

I would encourage you to search more from Google and be Specific with Your Question. Hope This would Help.

I am a Student
  • 1,570
  • 4
  • 21
  • 36
  • Thank you, i try find it on google but i can't find a solution. I just need to restore my first activity from background when i am on second activity and then do the contrary from the first activity to the second one, without lose the value changing the activity. I can try using the Share Preference method. Thank you so much and sorry if i can't be more specific. – Bacchelli Matteo Mar 14 '18 at 21:34