Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 FragmentActivity、一些片段和一个在后台运行的服务。是否可以从服务中检查特定片段是否可见?
查看if(YourFragment.this.isVisible())
if(YourFragment.this.isVisible())
public boolean isFragmentUIActive() { return isAdded() && !isDetached() && !isRemoving(); }
行得通。
检查下面的代码:
public class MyFragment extends Fragment @Override public void setMenuVisibility(final boolean visible) { super.setMenuVisibility(visible); if (visible) { ... } }
它来自这个线程。或者你也可以检查这个。