dav*_*ber 3 android android-fragments android-support-library
我正在使用Fragment带有 Android 支持库 v7 的类。在我Activity的onCreate()方法中,我创建了一堆片段并将它们存储到我的活动的属性中。
this.firstFragment = new FirstFragment();
this.secondFragment = new SecondFragment();
// and so on
Run Code Online (Sandbox Code Playgroud)
我使用导航抽屉模式在应用程序的片段之间切换。要更改活动片段,我使用以下代码。
// Replace the current content of the fragment holder with the selected section fragment.
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.container, selectedFragment).commit();
Run Code Online (Sandbox Code Playgroud)
这会导致调用onDestroy()已删除的片段。在调用片段后重用片段是否安全onDestroy(),或者我应该在每次向用户显示片段时重新创建片段。
这是时间与内存消耗的问题,因为至少其中一个片段需要一些时间来创建。
| 归档时间: |
|
| 查看次数: |
1777 次 |
| 最近记录: |