How to save number of times a user has tapped on a view

81 Views Asked by At

I am designing a simple application that will count how many times a user has tapped on a imageView. My question is what would be the best way of saving and reading this file. Any suggestions? I am thinking something like using Parse.com's local database. I have tried it, but I could not get it working the way I wanted. I am still a beginner, so please not so fancy suggestions.

2

There are 2 best solutions below

1
Adam Fręśko On BEST ANSWER

Simplest options is always thebest option, go with shared preferences

Here is simple tutorial from google http://developer.android.com/training/basics/data-storage/shared-preferences.html

It will store your data in application local file. Take a note of that there are different shared preferences in example getPreferences() will return file specific for activity you used this method. While getSharedPreferences() will return application global file.

0
NehaK On

Try to save data in SharedPreference. SharedPreference works like database for application on device that will be stored until any one has unistall app from device.

To create sharedPrefernce-

SharedPreferences prefs = this.getSharedPreferences(
      "com.example.app", Context.MODE_PRIVATE);

To store data -

prefs.edit().putInt("key", int_value).apply();

To retrieve data-

// use a default value 
int l = prefs.getLong("key", default_value);