0

I have a ToggleButton which calls my function and function calls service in it:

@CheckedChange(R.id.tbValetMode)
protected void toggleValetMode(boolean isChecked) {
    mPresenter.sendValetModeState(isChecked);
}

I activate the button and change the fragment, and when I return to the same fragment, the button looks deactivated. However, I called the service once in the background.

So when I press the button again, I get an error by the service.

I wrote a method to check the latest status of Vale Mode. This method returns data from the GET service.

public void checkValetMode(Boolean result) {
    tbValetMode.setChecked(result);
}

But the setChecked () method calls the button as if it was pressed again, and when I change the fragment and come back, the button appears to be open but I get an error because it calls the service again.

Expectation: To display the Toggle Button according to the response of the method returned by the GET Service, even if the fragment changes.

AnilF
  • 108
  • 7
  • When you reentered in the fragment check the service state if it's running then simple update the button state. To check service is running or not please move to this thread. https://stackoverflow.com/questions/17588910/check-if-service-is-running-on-android?lq=1 – Rehan Sarwar May 04 '20 at 12:40
  • @RehanSarwar, Since my service is running, I want to show this button as clicked. But .setClicked() function run service again. That is the problem. – AnilF May 04 '20 at 12:55
  • So you can check your service status in your button OnClick() method. – Rehan Sarwar May 04 '20 at 12:59

0 Answers0