DL : Apk??????
???? (Development Help)
DL 2.0????
-
??????????????????DL???(???lab??)
-
??????so?(???dev??)
DL?????
-
plugin????????????
-
???R??plugin??
-
plugin??Activity?FragmentActivity????????????
-
???????
-
?????????????????
-
??3?plugin?host??????
?1?????????????????
?2??????host????????plugin??? ?????????plugin???????host??????
?3??????plugin??????host??????????plugin??????host??????
-
????DL???jar??????????DL?????????????
-
??android2.x??
DL????
?????????????????????????activity?????????????????????????DL?????????????????????????????????????apk??????????????????apk??????????????????????apk??????????
????
???????????????apk???????????????????????????R??????????????????????apk?????????R???????????????????????id????????????????????apk???????????copy???????????????????????????????????????????????????????????????copy???????????????????????????????????????????????????????????apk??????????????????????????????????????????????????apk???????????????????????????????????????????????????????????????????????xml??????????????????????????????????????????????????????????????????????????????????????
?????activity???????ContextImpl????? ??activity??????mBase?????????Context?????????????????????????context??????????????????????????ContextImpl????????????????????????????????
/** Return an AssetManager instance for your application's package. */ public abstract AssetManager getAssets();
/** Return a Resources instance for your application's package. */ public abstract Resources getResources();
?????????????? ?????apk?????
protected void loadResources() {
try {
AssetManager assetManager = AssetManager.class.newInstance();
Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class);
addAssetPath.invoke(assetManager, mDexPath);
mAssetManager = assetManager;
}
catch (Exception e) {
e.printStackTrace();
}
Resources superRes = super.getResources();
mResources = new Resources(mAssetManager, superRes.getDisplayMetrics(),
superRes.getConfiguration());
mTheme = mResources.newTheme();
mTheme.setTo(super.getTheme());
}
??????????????????AssetManager??addAssetPath??????????apk???????Resources????addAssetPath???api?????????????????????????????????????????????zip??????????????apk????zip??????apk?????????????AssetManager????????AssetManager???????Resources????????????????apk??????????????????
/** * Add an additional set of assets to the asset manager. This can be * either a directory or ZIP file. Not for use by applications. Returns * the cookie of the added asset, or 0 on failure. * {
@hide
}
*/
public final int addAssetPath(String path) {
int res = addAssetPathNative(path);
return res;
}
?????????????
@Override
public AssetManager getAssets() {
return mAssetManager == null ? super.getAssets() : mAssetManager;
}
@Override
public Resources getResources() {
return mResources == null ? super.getResources() : mResources;
}
okay????????????apk??????R???????
activity???????
?????????????????apk??????????apk??activity???????????????activity??????????activity??????????????????????????activity???????????????????activity?????????????activity??????????????????????activity??????????????????onCreate?onStart?onResume?onPause????apk??activity????????activity??????????????????????????????????????????????????????Fragment?????????Fragment?3.0?????support-v4??????3.0???android???Fragment?????Activity???????????View?????Fragment???Activity??activity?????Fragment??????????????????apk??activity???????????activity?????Fragment?????activity??????????????activity????????????????apk????Fragment??????????????????????????Fragment???????????????
?????DL?????????????activity??????????????????????????????????????????????????????????????activity?????????????????????DLPlugin????????activity?DLProxyActivity??????activity??????????????????activity?????????????????????????????????????????????????????activity???????
public interface DLPlugin {
public void onStart();
public void onRestart();
public void onActivityResult(int requestCode, int resultCode, Intent data);
public void onResume();
public void onPause();
public void onStop();
public void onDestroy();
public void onCreate(Bundle savedInstanceState);
public void setProxy(Activity proxyActivity, String dexPath);
public void onSaveInstanceState(Bundle outState);
public void onNewIntent(Intent intent);
public void onRestoreInstanceState(Bundle savedInstanceState);
public boolean onTouchEvent(MotionEvent event);
public boolean onKeyUp(int keyCode, KeyEvent event);
public void onWindowAttributesChanged(LayoutParams params);
public void onWindowFocusChanged(boolean hasFocus);
public void onBackPressed();
...
}
????DLProxyActivity????
...
@Override
protected void onStart() {
mRemoteActivity.onStart();
super.onStart();
}
@Override
protected void onRestart() {
mRemoteActivity.onRestart();
super.onRestart();
}
@Override
protected void onResume() {
mRemoteActivity.onResume();
super.onResume();
}
@Override
protected void onPause() {
mRemoteActivity.onPause();
super.onPause();
}
@Override
protected void onStop() {
mRemoteActivity.onStop();
super.onStop();
}
...
??apk?????
???????????????apk????????????????????????apk?????????
-
??this?????????this??????????apk??activity?????activity??????????activity???this???????????this???????????context???activity???????????this?????
-
??that???this???????that?that?apk?activity???BaseActivity?????????apk?????????this???????????????????activity?anyway?that is better than this?
-
activity???????????????????that??????????????????api???????????????api?????that????????apk?????????????
-
???activity????????activity???????apk???activity????????apk??activity????????????????????BaseActivity???????startActivityByProxy?startActivityForResultByProxy????????LaunchMode?
-
??????Service?BroadcastReceiver???????????????????????????
???????
- DLIntent??????????intent????activity??????
- UI Bus
- ??android?????
??
??????????????/mnt/sdcard/DynamicLoadHost??????apk????????????????????apk?????demo????????demo?????????????????????activity??????????????R????????????????
nealgao???????logo?
????License
Copyright (C) 2014 singwhatiwanna(???) <[email protected]> collaborator:??,??? 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.