Coder Social home page Coder Social logo

mqync / cjframeforandroid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kymjs/cjframeforandroid

0.0 2.0 0.0 2.03 MB

Android插件开发框架,插件化开发不再神秘。

Home Page: http://www.kymjs.com

License: Apache License 2.0

Java 8.77% HTML 89.04% JavaScript 0.13% CSS 2.05%

cjframeforandroid's Introduction

logo CJFrameForAndroid简介

CJFrameForAndroid 是一个实现android插件化开发的框架。使用CJFrameForAndroid,apk动态加载不再是难题,更重要的是可以轻松实现插件与APP项目之间的解耦。


注: CJFrameForAndroid现已并入Android应用开发框架KJFrameForAndroid中,作为其插件化模块存在,此处更新将延后。

CJFrameForAndroid 相关链接

原理描述

CJFrameForAndroid的实现原理是通过类加载器,动态加载存在于SD卡上的apk包中的Activity。通过使用一个托管所,插件Activity全部事务(包括声明周期与交互事件)将交由托管所来处理,间接实现插件的运行。更多介绍:CJFrameForAndroid原理介绍
一句话概括:CJFrameForAndroid中的托管所,复制了插件中的Activity,来替代插件中的Activity与用户交互。

框架使用

●使用 CJFrameForAndroid 插件开发框架需要在你项目的AndroidManifest.xml文件中加入托管所的声明。

<activity android:name="org.kymjs.aframe.plugin.CJProxyActivity" />  <!-- 如果使用了插件Activity,需要添加 -->
<service android:name="org.kymjs.aframe.plugin.service.CJProxyService"/>  <!-- 如果使用了插件Service,需要添加 -->

●让插件应用中的Activity继承CJActivity,并且一切使用this调用的方法都使用that替代。例如this.setContentView();需要改为that.setContentView();
●插件中涉及到的Android权限,须在APP项目清单中具有声明。
●插件Activity跳转时,推荐使用CJActivityUtils类来辅助跳转。若一定要startActivity或startActivityForResult,在跳转过程中的Intent不能自己new,必须使用CJActivityUtils.getPluginIntent();
●在插件和APP两个工程中不能引用相同的jar包。解决办法是:在插件工程的项目中添加一个/cjlibs的文件夹,将需要调用的jar包放到这个文件夹中,并在插件项目目录下的.classpath中加入如下语句,系统会自动处理相关细节

<classpathentry kind="lib" path="cjlibs"/>

示例工程运行

下载KJFrameForAndroid项目,并运行demo;下载插件化演示Demo,点击KJFrameForAndroid的Demo中Plugin模块根据提示操作


注意事项

●APP项目和插件项目中,都需要使用到CJFrameForAndroid的jar包。
●在项目中必须加入托管所声明。
●在开发插件的时候,必须继承CJ框架相应基类;
●在插件的Activity中,一切使用this的部分必须使用that来替代;
●在插件Activity跳转时,推荐使用CJActivityUtils类来辅助跳转;
●在插件和APP两个工程中不能引用相同的jar包;

名词解释

APP项目:指要调用插件apk的那个已经安装到用户手机上的应用。
插件项目:指没有被安装且希望借助已经安装到手机上的项目运行的apk。
插件化:Activity继承自CJActivity,且与APP项目jar包冲突已经解决的插件项目称为已经被插件化。
Activity事务:在CJFrameForAndroid中,一个Activity的生命周期以及交互事件统称为Activity的事务。
托管所:指插件中的一个委派/代理Activity,通过这个Activity去处理插件中Activity的全部事务,从而表现为就像插件中的Activity在运行一样。

许可

Copyright (c) 2014, Zhang Tao.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

cjframeforandroid's People

Contributors

kymjs avatar

Watchers

James Cloos avatar kahal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.