Skip to content

Commit defed81

Browse files
committed
improve UI Container and URL Mapping
1 parent 27020c1 commit defed81

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Android Dynamic Loader is a plugin system. The host application is like a browser, but instead of load web pages, it load plugins which runs natively on Android system.
44

5-
You can download the demo from <https://github.com/mmin18/AndroidDynamicLoader/raw/master/host.apk>
5+
You can download the demo from <https://github.com/mmin18/AndroidDynamicLoader/raw/master/host.apk> (35k).
66

77
## How to run the sample plugins
88

@@ -23,16 +23,37 @@ If it shows "device not found", make sure your phone is connected or simulator i
2323

2424
Since we don't specific a default entry in **workspace.properties**, it will popup a window and let you choose one. I suggest bitmapfun.
2525

26+
## About UI Container
27+
28+
In a normal Android application, we use Activity as the root UI container. But since Activity is registered in AndroidManifest.xml, and we can't modify manifest in runtime, we must find an alternative UI container - Fragment.
29+
30+
The Fragment itself, interduced in Android 3.0 Honeycomb, is a perfect UI container, and it has lifecycle and state management.
31+
32+
Once the plugin and its dependency is downloaded, an Activity (MainActivity.java) will be started, create an instance of the specific fragment, and add the fragment into the root view.
33+
34+
See the [HelloFragment.java](https://github.com/mmin18/AndroidDynamicLoader/blob/master/workspace/sample.helloworld/src/sample/helloworld/HelloFragment.java) sample.
35+
2636
## About URL Mapping
2737

28-
// TODO:
38+
Since we use Fragment as UI container, each page is implemented in Fragment instead of Activity. So how do we start a new page?
39+
40+
We use URL, just like a browser does. For instance, in a browser, we open `http://mydomain.com/helloworld.html`. In plugins, we open `app://helloworld`.
41+
42+
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("app://helloworld"));
43+
startActivity(i);
44+
45+
Each host is mapped to a single fragment, you define the url mapping table in **project/fragment.properties**.
46+
47+
See the [helloworld fragment.properties](https://github.com/mmin18/AndroidDynamicLoader/blob/master/workspace/sample.helloworld/fragment.properties) sample.
2948

3049
## Folders
3150

32-
**/Host** contains the host application (build as host.apk).
51+
`/Host` contains the host application (build as host.apk).
52+
53+
`/tools/update.sh` checks your environment and helps you config your plugins. You should always run it once after git clone or create a new plugin.
3354

34-
**/tools/update.sh** checks your environment and helps you config your plugins. You should always run it once after git clone or create a new plugin.
55+
`/workspace/sample.helloworld` is a most simple plugin.
56+
`/workspace/sample.helloworld/fragment.properties` defines the url mapping of your fragments.
3557

36-
**/workspace/sample.helloworld** is a most simple plugin.
37-
**/workspace/sample.helloworld/fragment.properties** defines the url mapping of your fragments.
58+
`/site/***/site.txt` is the definition file for all the plugins files, dependency and fragments url mapping table.
3859

0 commit comments

Comments
 (0)