package com.qihoo360.replugin.sample.host;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.qihoo360.replugin.RePlugin;

/**
 * 打开插件中的Fragment
 * <p>
 * 作者 coder
 * 创建时间 2017/7/6
 */

public class PluginFragmentActivity extends FragmentActivity {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //注册相关Fragment的类
        //注册一个全局Hook用于拦截系统对XX类的寻找定向到Demo1中的XX类主要是用于在xml中可以直接使用插件中的类
        RePlugin.registerHookingClass("com.qihoo360.replugin.sample.demo1.fragment.DemoFragment", RePlugin.createComponentName("demo1", "com.qihoo360.replugin.sample.demo1.fragment.DemoFragment"), null);
        setContentView(R.layout.activity_plugin_fragment);


        //代码使用插件Fragment
        ClassLoader d1ClassLoader = RePlugin.fetchClassLoader("demo1");//获取插件的ClassLoader
        try {
            Fragment fragment = d1ClassLoader.loadClass("com.qihoo360.replugin.sample.demo1.fragment.DemoCodeFragment").asSubclass(Fragment.class).newInstance();//使用插件的Classloader获取指定Fragment实例
            getSupportFragmentManager().beginTransaction().add(R.id.container2, fragment).commit();//添加Fragment到UI
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}

@@ -489,16 +489,668 @@
 State);%0A
+%0A        /**%0A         * %E6%B3%A8%E6%84%8F%EF%BC%9A%0A         *%0A         * %E5%A6%82%E6%9E%9C%E4%B8%80%E4%B8%AA%E6%8F%92%E4%BB%B6%E6%98%AF%E5%86%85%E7%BD%AE%E6%8F%92%E4%BB%B6%EF%BC%8C%E9%82%A3%E4%B9%88%E8%BF%99%E4%B8%AA%E6%8F%92%E4%BB%B6%E7%9A%84%E5%90%8D%E5%AD%97%E5%B0%B1%E6%98%AF%E6%96%87%E4%BB%B6%E7%9A%84%E5%89%8D%E7%BC%80%EF%BC%8C%E6%AF%94%E5%A6%82%EF%BC%9Ademo1.jar%E6%8F%92%E4%BB%B6%E7%9A%84%E5%90%8D%E5%AD%97%E5%B0%B1%E6%98%AFdemo1(host-gradle%E6%8F%92%E4%BB%B6%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90)%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%89%A7%E8%A1%8C%E8%AF%B8%E5%A6%82RePlugin.fetchClassLoader(%22demo1%22)%E7%9A%84%E6%93%8D%E4%BD%9C%EF%BC%9B%0A         * %E5%A6%82%E6%9E%9C%E4%B8%80%E4%B8%AA%E6%8F%92%E4%BB%B6%E6%98%AF%E5%A4%96%E7%BD%AE%E6%8F%92%E4%BB%B6%EF%BC%8C%E9%80%9A%E8%BF%87RePlugin.install(%22/sdcard/demo1.apk%22)%E5%AE%89%E8%A3%85%E7%9A%84%EF%BC%8C%E5%88%99%E5%BF%85%E9%A1%BB%E5%8A%A8%E6%80%81%E8%8E%B7%E5%8F%96%E8%BF%99%E4%B8%AA%E6%8F%92%E4%BB%B6%E7%9A%84%E5%90%8D%E5%AD%97%E6%9D%A5%E4%BD%BF%E7%94%A8%EF%BC%9A%0A         * PluginInfo pluginInfo = RePlugin.install(%22/sdcard/demo1.apk%22);%0A         * RePlugin.preload(pluginInfo);//%E8%80%97%E6%97%B6%0A         * String name = pluginInfo != null ? pluginInfo.getName() : null;%0A         * ClassLoader classLoader = RePlugin.fetchClassLoader(name);%0A        */%0A%0A        boolean isBuiltIn = true;%0A        String pluginName = isBuiltIn ? %22demo1%22 : %22com.qihoo360.replugin.sample.demo1%22;%0A%0A
         
@@ -1361,23 +1361,26 @@
 entName(
-%22demo1%22
+pluginName
 , %22com.q
@@ -1501,17 +1501,16 @@
 ment);%0A%0A
-%0A
         
@@ -1588,23 +1588,26 @@
 sLoader(
-%22demo1%22
+pluginName
 );//%E8%8E%B7%E5%8F%96%E6%8F%92%E4%BB%B6

Make Fragment sample stronger