0
@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if(Tb.isChecked()){
        android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals("120000");
    }else{
        android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals("300000");
    }
}

I'm developing a widget which has the option for getting updates every 2 min and 30 min. so I made a toggle button to switch between time. The above block of code I'm using to enable the Toggle button known as Tb. The app is not showing errors, but it doesn't seem to be working. Can somebody check my code for errors.

David Manpearl
  • 12,362
  • 8
  • 55
  • 72
AACaN
  • 90
  • 2
  • 8

1 Answers1

0

This code is not setting anything.

You are testing ACTION_APPWIDGET_UPDATE to see if it is equal to "120000" or "300000". ACTION_APPWIDGET_UPDATE is a String constant that is always equal to "android.appwidget.action.APPWIDGET_UPDATE".

Therefore, each of those lines do nothing and the equals() test which is not evaluated always returns false.

Good news is that the following lines of code are probably getting correctly triggered, they just are not the correct way to set interval values:

android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals("120000");
android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals("300000");

To fix this problem, find another way to set your 2 minute and 30 minute interval values.

David Manpearl
  • 12,362
  • 8
  • 55
  • 72
  • As in the question i do not save it. just code it into a toggle button, so i can name the toggle button as express updates or something in the UI so user can turn it on to get updates quickly. that's all. – AACaN Mar 21 '13 at 07:23
  • Where to save the update interval in the new widget with a CheckBox that you are developing? Is your widget a class that is extending CheckBox? If so, then we can add the interval as a class variable. Otherwise, please share more about how the interval is accessed and used so we can decide how to change its setting. – David Manpearl Mar 21 '13 at 07:30