I have used ToggleButton in my MAINACTIVITY.java. When it is on am fetching the current location from another class GPSLOCATION.java and updating to server.
<ToggleButton
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onToggleClicked" />
public void onToggleClicked(View view) {
boolean on = ((ToggleButton) view).isChecked();
if (on) {
update_alert();
} else {
timerAlert.cancel();
}
}
But since its run by using TimerTask i.e., If TOGGLEBUTTON is ON then for every one minute LOCATION is fetched and updated in server. Instead I want to get the state of TOGGLEBUTTON in the GPSLOCATION.java under onLocationChanged method and if ON then I need to update it to server, I know it is possible can anyone help me to get rid of this scenario.