Android中Fragment的生命周期
- 添加到界面上
FragmentManager manager = getSupportFragmentManager() ; FragmentTransaction transaction = manager.beginTransaction() ; fragment = new CastMainFragment(); transaction.add(R.id. frame, fragment ); transaction.commit() ;
走了一下生命周期的方法: onAttach onCreate onCreateView onStart onResume
- 从界面上移除
getSupportFragmentManager() .beginTransaction() .remove(fragment ) .commit();
生命周期: onPause onStop onDestroyView onDestroy onDetach