0

I am making a Music Player in Android. Data about mp3 files is accessed from mediastore.audio.media. I have added an additonal textview field and assigned it to 0,this textview displays how many times this song has been listened. so everytime the user plays the song, the textview value is incremented by 1.

I load the data, i increment the textview, it works in all scenarios , that is oncompletion,next,previous,play,onitemclick it updates the value of the textview.

I close down my app and i restart it.after restarting in the onCreate method of main activity listview gets popluated,and the incremented values of the textview are set back to 0. that is the incrementd values are not stored.

How should i store the values and reflect it when the user restarts the app, or even after the user uninstalls the app and decides to download it back ? how should i store the incremented values ?

disconights01
  • 11
  • 1
  • 1

2 Answers2

0

If u want the values even after user uninstalls the app then shared preferences are of no use as they will be cleared.

You can write the data to a file on the disk and retrieve the value when activity starts. Here's the link on the android developers site about data storage :Data Storage

Cheers : )

vishnus
  • 728
  • 2
  • 7
  • 20
0

As you want to store one value per song you should be going with sqlite database with a table in which you will save listen count against song ID.

read more about how to use database in android.

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78