-1

I've given a task to create a simple counter app. in which user can update counter in both forward "Pressing + button" as well as in backward direction (Pressing - button) and also user can reset counter by pressing "Clear Button".

And last value should be stored in app when user closed app. i.e. if counter is on "50" and user closed app. after relaunching app counter should be start from "50"

I don't know how to store last value in app and retrieve it after relaunching app.

App ScreenShot

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
hassanrazadev
  • 626
  • 9
  • 15

1 Answers1

0

You can override onBackPressed method and store value in shared preferences.

Ahmad Sadiq
  • 153
  • 1
  • 1
  • 8
  • Kindly tell me in little detail. – hassanrazadev Apr 22 '18 at 13:25
  • There is an onBackPressed method which is called when back button is pressed you can override this method, secondly shared preferences are used to store values permanently, so it will be wise to store value in shared preferences so you can later you them.Read this https://developer.android.com/training/data-storage/shared-preferences.html – Ahmad Sadiq Apr 22 '18 at 22:04
  • https://www.youtube.com/watch?v=fJEFZ6EOM9o – Ahmad Sadiq Apr 24 '18 at 20:55