Search code examples
androidmultithreadingpreferences

Performing an action when a listpreference option is selected


Sorry I had to rephrase my question, I have a list preference with some option

enter image description here

I want to change the value of a variable depending on the option selected. I have no idea how to get the selected index or where to start from.


Solution

  • First, start by throwing out that code you posted. :) You don't want to use a thread for scheduled updates, you want to use the AlarmManager.

    The reason for this is that Android might kill your running app at any time. When an alarm fires it will wake up your app as needed, starting it from scratch if necessary so that it can run.