Android Developer Introduction To Codename One
Codename One allows Android developers familiar with Java and Eclipse (or NetBeans) to instantly get started building native applications for Android, iPhone, Windows and other platforms!
Unlike Google's Android tools when you develop using Codename One you enjoy:
To learn more about Codename One in general you can go to our developer section. Read below for information of Codename One equivalents to common Android features.
Unlike Google's Android tools when you develop using Codename One you enjoy:
- A fast simulator (unlike the unusable Android emulator).
- Standard Java debugging and profiling tools actually work
- Drag and drop developement (if you want to use them)
- No need to prepare resources for every resolution (our tool designer tool handles that).
- No need to deal with manifests and permissions, we automatically detect and apply the necessary permissions.
- Codename One hides the differences between versions on Android such as Gingerbread and Jellybean, a Codename One application will default to adapting to the behavior of the Android version it is running on
- Resources can be downloaded dynamically and aren't compiled into the APK which means you can integrate UI resources from 3rd parties too
- Component hierarchy (views) is much simpler in Codename One since the platform is designer for application developers and not for OS developers.
To learn more about Codename One in general you can go to our developer section. Read below for information of Codename One equivalents to common Android features.
Layouts
In Android developers build their user interfaces in XML by nesting layout views and view elements one within another (you can write Android apps in code but that isn't as common). These elements are translated by the compiler and in order to bind code to them you need to "find" them by their ID to use them. Codename One differs in several ways:
E.g. Android's linear layout is essentially very simiar to the box layout in Codename One. So to arrange components in a row in Codename One we can do something like:
- You can build Codename One applications either via the GUI builder (in which case you use a findXXX() method to locate the component) or write Java source code manually.
- Component is Codename One's equivalent of a view, Container derives from Component.
- All layouts are applied to the Container class essentially decoupling layout from Container hierarchy
E.g. Android's linear layout is essentially very simiar to the box layout in Codename One. So to arrange components in a row in Codename One we can do something like:
You can do the same with the GUI builder as well using simple drag and drop.
To read more about the different types of layouts and how they can be nested/used you can follow the section on layout managers in the developer guide.
To read more about the different types of layouts and how they can be nested/used you can follow the section on layout managers in the developer guide.
Fragments
Fragments essentially solve an issue with Android which mixed Activities and Views in a hierarchy creating a somewhat complex scenario to support a very dynamic architecture.
This concept is powerful, yet isn't portable, convenient or robust. Fragments become unnecessary because of the much simpler Codename One hierarchy.
This concept is powerful, yet isn't portable, convenient or robust. Fragments become unnecessary because of the much simpler Codename One hierarchy.
Multiple DPI's & 9-Patch Borders
Codename One supports a multi-image format which is roughly identical to the multiple DPI directories commonly used in Android. Unlike Android the Codename One designer tool automatically scales the images to all the resolutions (using high quality scaling algorithm) saving you the need to maintain multiple resolution support.
The same is true with Codename One's 9-part image borders. However, unlike Androids very elaborate 9-patch borders Codename One borders are far simpler.
Codename One uses tiling for border images (instead of scaling) and breaks the images down, it also includes an image cutting wizard and internally cuts the images to 9-pieces.
Android's 9-patch images are VERY powerful but also very hard to implement on all platforms in a performant way. They are also a very difficult concept to grasp for most developers.
The same is true with Codename One's 9-part image borders. However, unlike Androids very elaborate 9-patch borders Codename One borders are far simpler.
Codename One uses tiling for border images (instead of scaling) and breaks the images down, it also includes an image cutting wizard and internally cuts the images to 9-pieces.
Android's 9-patch images are VERY powerful but also very hard to implement on all platforms in a performant way. They are also a very difficult concept to grasp for most developers.
Activities
Codename One has its own lifecycle object which acts a bit more like an application than the activity does, its somewhat simpler to program to.
Codename One supports firing intents although that is mostly Android specific and won't work on other platforms.
Codename One supports firing intents although that is mostly Android specific and won't work on other platforms.
Android Specific Features
You can invoke "native" Android code from Codename One without breaking the portability of Codename One. Follow the native code section in the developer guide to understand how this can be accomplished. You can also add things to the manifest etc. if required by your native code.