문제

I am working on an application that does http requests to a server.

I have a TabBarController extending FragmentActivity that controls the fragments through 3 buttons. Each button shows a specific fragment and hides the others.

I want to do a http request every time I open one of those fragments. I tried using onResume in the fragment I want this to happen, however it won't work unless the TabBarController activity pauses first.

I tried searching things about this but nothing I found worked.

Thank you in advance.

도움이 되었습니까?

해결책

The fragments are still running when you hide them, so having checks in onResume() would not work.

You can instead do something like

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
  super.setUserVisibleHint(isVisibleToUser);
  if (isVisibleToUser) {
    // onResume() equivalent here
    // send HTTP request or ...
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top