Android determines whether the current fragment is visible (visible)

Source: Internet
Author: User

Determine if the current fragment is visible
Public abstract class Basefragment extends Fragment {

/**/protected  boolean isVisible; @Overridepublicvoid Setuservisiblehint (Boolean isvisibletouser) {    super.setuservisiblehint (isvisibletouser);     if (Getuservisiblehint ()) {        true;     Else {        false;    }}

}

The fragment lifecycle interacts with the activity life cycle.

The life cycle of an activity that has fragment directly affects the life cycle of the fragment, so that callbacks for each life cycle of the activity have a similar callback for fragment. For example, when activity receives a onpause () callback, each fragment in the activity receives a onpause () callback.
Multi-screen fit-if you want to develop an app on Android, you have to consider the problem of fragmentation, or you must consider a multi-screen adaptation.

Note: According to the requirements, judge the current fragment, and then go to request data or other operations

Second, there are times, we use the form of tablayout+fragment, in a certain fragment network request operation, go to other pages to switch back and forth when the network request, then we just add a boolean tag variable, the request after the end of the change tag, Make a judgment on the network request, it will not repeat the request.

Android determines whether the current fragment is visible (visible)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.