标签:mode ado 内存泄漏 toolbar vat flow begin 需要 switch
public void initFragment(){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fl_container,onCreteFragment());
ft.commitAllowingStateLoss();//允许丢失,一般可以不用这个采用commit()替代
}
public void initFragment(){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.fl_container,onCreteFragment());
ft.commitAllowingStateLoss();//允许丢失,一般可以不用这个采用commit()替代
}
public void switchFragment(Fragment from, Fragment to) {
FragmentTransaction mFragmentTransaction = getSupportFragmentManager().beginTransaction();
if (!to.isAdded()) { // 先判断是否被add过
mFragmentTransaction.hide(from).add(R.id.fl_container, to)
.commit(); // 隐藏当前的fragment,add下一个到Activity中
} else {
mFragmentTransaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
}
}
public void switchFragment(Fragment from, Fragment to) {
FragmentTransaction mFragmentTransaction = getSupportFragmentManager().beginTransaction();
if (!to.isAdded()) { // 先判断是否被add过
mFragmentTransaction.hide(from).add(R.id.fl_container, to)
.commit(); // 隐藏当前的fragment,add下一个到Activity中
} else {
mFragmentTransaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
}
}
public static class MyOnBackListener implements BaseFragment.OnBackListener {
private final WeakReference<BaseFragment> mBaseFragment;//目的Fragment
private final WeakReference<BaseFragmentActivity> mBaseActivity;
/**
* @param toFragment 跳转目的Fragment
* @param baseActivit 当前BaseActivity
*/
public MyOnBackListener(BaseFragment toFragment,BaseFragmentActivity baseActivit) {
mBaseFragment =new WeakReference<>(toFragment);
mBaseActivity =new WeakReference<>(baseActivit);
}
@Override
public void back(BaseFragment baseFragment) {
BaseFragmentActivity baseActivity = mBaseActivity.get();
BaseFragment baseFragment2 = mBaseFragment.get();
if (baseActivity !=null&& baseFragment2 !=null&&baseFragment!=null){
baseActivity.switchFragment(baseFragment,baseFragment2);
}
}
}
public static class MyOnBackListener implements BaseFragment.OnBackListener {
private final WeakReference<BaseFragment> mBaseFragment;//目的Fragment
private final WeakReference<BaseFragmentActivity> mBaseActivity;
/**
* @param toFragment 跳转目的Fragment
* @param baseActivit 当前BaseActivity
*/
public MyOnBackListener(BaseFragment toFragment,BaseFragmentActivity baseActivit) {
mBaseFragment =new WeakReference<>(toFragment);
mBaseActivity =new WeakReference<>(baseActivit);
}
public void back(BaseFragment baseFragment) {
BaseFragmentActivity baseActivity = mBaseActivity.get();
BaseFragment baseFragment2 = mBaseFragment.get();
if (baseActivity !=null&& baseFragment2 !=null&&baseFragment!=null){
baseActivity.switchFragment(baseFragment,baseFragment2);
}
}
}
private void initLocalFragment() {
mRfbf = new RecyclerFabBehaviorFragment();
mRfbf.setOnBackListener(new MyOnBackListener(mStartRecycFragment,this));
}
private void initLocalFragment() {
mRfbf = new RecyclerFabBehaviorFragment();
mRfbf.setOnBackListener(new MyOnBackListener(mStartRecycFragment,this));
}
@Override
public void click(View view, int position) {
switch (position){
case 0:
switchFragment(mStartRecycFragment, mRfbf);
break;
}
}
public void click(View view, int position) {
switch (position){
case 0:
switchFragment(mStartRecycFragment, mRfbf);
break;
}
}
TabyoutViewPagerFragment extends BaseFragment
private void initToolbar() {
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnBackListener!=null){
mOnBackListener.back(TabyoutViewPagerFragment.this);
}
}
});
}
private void initToolbar() {
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mOnBackListener!=null){
mOnBackListener.back(TabyoutViewPagerFragment.this);
}
}
});
}
annotationProcessor ‘com.zhy.fabridge:fabridge-compiler:1.0.0‘
implementation ‘com.zhy.fabridge:fabridge-api:1.0.0‘
annotationProcessor ‘com.zhy.fabridge:fabridge-compiler:1.0.0‘
implementation ‘com.zhy.fabridge:fabridge-api:1.0.0‘
Fabridge.call(getActivity(), EVENT_CLICK, "来了");
Fabridge.call(getActivity(), EVENT_CLICK, "来了");
@FCallbackId(id = FabrigeSampleFragment.EVENT_CLICK)
public void menuItemClick(String title)
{
Toast.makeText(this, ""+title+","+Thread.currentThread().getName(), Toast.LENGTH_SHORT).show();
}
x
id = FabrigeSampleFragment.EVENT_CLICK) (
public void menuItemClick(String title)
{
Toast.makeText(this, ""+title+","+Thread.currentThread().getName(), Toast.LENGTH_SHORT).show();
}
标签:mode ado 内存泄漏 toolbar vat flow begin 需要 switch
原文地址:https://www.cnblogs.com/jeffery336699/p/9288630.html