• onActivityResult 解耦 不需要一层一层的写


    public abstract class AbsShareMessageTemplates implements IShareMessageTemplates {
        public final static String SHARE_EMPTY_FRAGMENT_TAG = "share_empty_fragment";
    
        public AbsShareMessageTemplates(Activity activity){
            if (activity instanceof FragmentActivity) {
                FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager();
                LifeCycleFragment emptyFragment = new LifeCycleFragment();
                emptyFragment.setIShareMessageTemplates(this);
                FragmentTransaction fragmentTransaction = fm.beginTransaction();
                fragmentTransaction.add(emptyFragment, SHARE_EMPTY_FRAGMENT_TAG).commitAllowingStateLoss();
            }
        }
    
        public static class LifeCycleFragment extends Fragment{
            private IShareMessageTemplates iShareMessageTemplates;
    
            public void setIShareMessageTemplates(IShareMessageTemplates iShareMessageTemplates) {
                this.iShareMessageTemplates = iShareMessageTemplates;
            }
    
            @Override
            public void onActivityResult(int requestCode, int resultCode, Intent data) {
                super.onActivityResult(requestCode, resultCode, data);
                if (iShareMessageTemplates != null) {
                 iShareMessageTemplates.handleActivityResult(requestCode, resultCode, data);
                }
            }
        }
    }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            FragmentManager fm = getSupportFragmentManager();
            if(fm.getFragments()!=null && !fm.getFragments().isEmpty()) {
                for (Fragment fragment : fm.getFragments()) {
                    if (null != fragment&&TextUtils.equals(fragment.getTag(), AbsShareMessageTemplates.SHARE_EMPTY_FRAGMENT_TAG)) {
                        fragment.onActivityResult(requestCode, resultCode, data);
                    }
                }
            }
        }
  • 相关阅读:
    JavaScript-5(数组)
    JavaScript-作用域-预解析
    JavaScript-日历生成器
    JavaScript-8行5列表格
    package XXX.i386.rpm is not installed(检查在Linux上安装Oracle所需的pkg时)
    ubuntu13.04下安装jdk7
    Linux远程传输命令之scp使用方法
    Mac OS X中MacPorts安装和使用
    第一天 Linux 是什么
    Javascript与当前项目的思考
  • 原文地址:https://www.cnblogs.com/zhaozilongcjiajia/p/12923557.html
Copyright © 2020-2023  润新知