我在ViewPager中有两个片段,而在第一个片段中我又添加了两个子片段,这两个子片段中有视图和异步调用。现在,当我从 viewPager 的一个片段滑动到另一个片段然后返回第一个片段时,所有视图都保留在子片段中。
当从 viewpager 的第一个片段滑动到其他片段时,我希望子片段的视图和异步调用为 null 或销毁,以避免内存泄漏。一切正常。
我在第一个视图寻呼机片段中添加了两个片段,如下所示:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.strongholdapps.scannertr.tablayout.Fragments.FirstFragment">
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:name="com.strongholdapps.scannertr.tablayout.Fragments.FirstCurrencyFragment"
android:id="@+id/firstCurrency"/>
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:name="com.strongholdapps.scannertr.tablayout.Fragments.FirstCurrencyFragment"
android:id="@+id/secondCurrency"/>
</LinearLayout>