Following the Script

 

Unlike other mobile‑device operating systems, Android has no restrictions on what you can run on it, so long as you can do it in Java using the Dalvik VM. This includes incorporating your own scripting language into your application, something that is expressly prohibited on some other devices.

One possible Java scripting language is BeanShell.[22]BeanShell gives you Java‑compatible syntax with implicit typing and no compilation required.

So, to add BeanShell scripting, you need to put the BeanShell interpreter’s JAR file in your directory. The 2.0b4 JAR available for download from the BeanShell site, unfortunately, does not work out of the box with the Android 0.9 and newer SDKs, perhaps due to the compiler that was used to build it. Instead, you should probably check out the source code from Subversion[23] and execute ant to build it, then copy the resulting JAR (in BeanShell’s directory) to your own project’s . Or just use the BeanShell JAR that accompanies the source code for this book, in the project available in the Source Code area at http://apress.com.

From there, using BeanShell on Android is no different from using BeanShell in any other Java environment:

1. Create an instance of the BeanShell class.

2. Set any globals for the script’s use via .

3. Call to run the script and, optionally, get the result of the last statement.

For example, here is the XML layout for the world’s smallest BeanShell IDE:

 

 

Couple that with the following activity implementation:








Дата добавления: 2015-05-16; просмотров: 675;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.004 сек.