tags:

views:

157

answers:

3

I have a Seekbar and I want to save the state to database when the progress is changed.

I am wondering in which event to put my code onProgressChanged vs. onStopTrackingTouch?

A: 

Unless you have reason to believe that the application will often crash in the middle of the gesture and you need to save where the user was at that time, I would recommend onStopTrackingTouch.

jqpubliq
+1  A: 

I would use onProgressChanged if you need to update any elements of the UI as the user is sliding the progress bar.

I would wait for onStopTrackingTouch to actually update the database.

mbaird
+1  A: 

I am going to disagree with both mbaird and jqpubliq, for one simple reason: they assume the user is using a touchscreen.

Most Android devices have touchscreens. Not all will. For example, there are firms developing Android set-top boxes (think Android equivalents of Roku or Boxee Box). Most televisions are not touchscreens.

Now, if you want your application to only be usable with a touchscreen -- and you have set the appropriate <uses-configuration> elements in your manifest -- onStopTrackingTouch() may be reliable for detecting a progress change.

Personally, I would update the database on neither onProgressChanged() nor onStopTrackingTouch(), but at the point when the user does something positive to indicate they want to persist the current screen's contents -- pressing the BACK button, clicking a Save button, etc. But I certainly would not rely on onStopTrackingTouch() unless you are developing a touchscreen-only app.

CommonsWare