Introduction
Recent industry reports have indicated that over 70% of tablets and smartphones worldwide use the Android* OS. Development of Android Apps is becoming more popular day by day. In this article I want to share some sample code for Android using Intel® Integrated Native Developer Experience (Intel® INDE) integrating to Eclipse*. Intel® INDE provides a collection of “best-in-class” tools and libraries that help you quickly and easily create cross-platform apps that take advantage of the native performance of your underlying Android* or Windows* platform.
Install Development Tools
Before the introduction of INDE, you must download and install Eclipse* IDE, ADT Plugin for Eclipse, JDK and JRE, Android SDK. Now, just install only 64 bit JDK as a pre-requisite, everything else will be installed by INDE.
INDE Installation
To install Intel® INDE 2015, select the Evaluate Ultimate Edition option and click Next (note that you can also choose Install Starter Edition Option).
Select Eclipse* Development Environment option and click Next.
Choosing this option will download and install all the necessary tools, including Eclipse* itself, the Eclipse Plugins for Intel® INDE, Android Development Tools, Android NDK, and other relevant tools.
Creating a Sample App for Android
Let’s create a sample native app. Start Eclipse for Android ADT located in C:\Intel\INDE\IDEintegration\ADT\eclipse and select the desired workspace location.
From the File menu, select New/Intel x86 Native Android Project:
- First, run Eclipse and select File | New | Project…, in the list. Select Android | Android Application Project and click Next.
- On a dialog box called Setup Wizard New Android App, fill in the following text fields with your information:
- Application name - a descriptive name for the application, like “MyApp”
- Project Name - enter the name of the project, like “MyProject”.
- Package Name - enter a unique name for the package, like “ru.egorfilimonov.indeapp”.
- Minimum Required SDK - select the minimum supported platform. In the Target SDK platform, choose a value under which you will write a program. You can leave the default value if you want.
- Compile With - the default is the latest version of Android. We do not need to change this.
- Theme - choose a theme from the list of standard themes for your application or leave it unchanged.
- After filling in all the fields, click Next.
- Leave the Create custom launcher icon box checked, so you can use your own icon for the program.
- Leave the Create activity box checked as well.
- Do not check the Mark this project as library as box, as you are not creating a library.
- Leave the Create Project in Workspace box checked so that all your projects will be stored in a special folder C:\Users\UserName\workspace
When finished with these settings, click Next. Here we need to choose the appearance of the application screen. Create Activity - most applications targeted for Android have a screen called Create Activity that features a Project Wizard offering several templates that can help you build your app. Choose Blank Activity template.
Click Finish when done. A new project will be created now.
Working with a Project
The “Hello, World!” program is already built into any new project, so you do not need to write anything. You just need to start the project and get ready to program! Expand the src folder and the ru.<…>.helloworld subfolder, which is the name of your package, to see the MainActivity.java file. Double-click the file to open it in the Code Editor. The IDE has already generated the minimum code required for the MainActivity.java file. It is even easier to open the file via the toolbar, which is located on the form. Find the button of MainActivity and select Open MainActivity.
Look at the code:
package ru.egorfilimonov.indeapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is the file where the name of the class MainActivity coincides with Java file (this rule established language Java). The first line is the name of the package (Package Name). Next, there are lines that import the required classes for the project. If warning icons appear to the left of the class names, read the messages that pop up when your cursor is over them. For example, if you see a yellow triangle with an exclamation mark and the message is that this class is not used, you can safely remove the extra lines.
After the MainActivity is the announcement of the class that inherits (extends) from the abstract class ActionBarActivity. In the class we see the method onCreate (). It is called when the application creates and displays the markup activity. Let’s examine the method's code.
Line super.onCreate (savedInstanceState) is the parent class that performs the operations necessary for the activity. You do not need to touch this line; leave it unchanged.
The second line setContentView (R.layout.activity_main); is of more interest. The setContentView (int) method connects the content of the markup file. In the argument we specify the file name without the extension from a folder res / layout /. By default, it creates a project file called activity_main.xml.
After the onCreate () method, the onCreateOptionsMenu () and onOptionsItemSelected () methods are associated with the handling menu.
In the file activity_main.xml you can design visual part of your app.
Running Application in Android Emulator
For running your first app in Android Emulator, select Run/Run Configurations from the menu, click on New Launch Configuration button (the first button), enter the name of your configuration and select the project.
Select the Target Tab and select Intel_Nexus_7_x86 as a target, hit Apply and Run buttons:
After the simulator starts up and you can see your application up and running
Conclusion
Intel INDE will help you develop apps that run at native performance on each platform. Developing native Android apps using INDE is a very simple task. You don’t have to spend months learning to optimize for the performance and power characteristics of each and every target device.
About the Author
Egor Filimonov works in the Software & Services Group at Intel Corporation. He is a student of Lobachevsky State University in Nizhni Novgorod, Russia. His faculty is mechanic and mathematics. His specialty is applied mathematics and informatics. His main interest is HPC (High Performance Computing) and mobile technologies.