After we have created an application we would want to test and run it, obviously !
So now lets see how we can do so. We first create a sample hello world program and then run it.
While using the Eclipse IDE you would see that the project wizard by default provides us with a ready made, ready to run Hello world program. That means that we already get the following:
So now lets see how we can do so. We first create a sample hello world program and then run it.
While using the Eclipse IDE you would see that the project wizard by default provides us with a ready made, ready to run Hello world program. That means that we already get the following:
- layout - The graphical user interface(GUI)on which we see the output and interact with our application.It is a .xml layout file.It is located in the directory workspace\your_application\res\layout\activity_main.xml
- src - The .java class which has the code and all the logic enables us to interact with the GUI. It is located in the directory workspace\your_application\src\com\tutorial\example\MainActivity.java
- Android manifest - The .xml file which enables us to debug our application.Without this the debugging can not be done.It is located in the directory workspace\your_application\AndroidManifest.xml
- string - Is a .xml file that helps us to reference resources by using the name attribute of it.It is located in the directory workspace\your_application\res\values\strings.xml.
So the ready made code that we get is :
MainActivity.java
public class MainActivity extends Activity//Create a new activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);// Set the content on a particular layout .
}
}
String.xml
<resources>
<string name="app_name">examples</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutorial.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="6"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
so without even writing a single line of code we get this.:)
Running application on AVD:
- Go to window in the Eclipse IDE
- Select AVD manager
- create new AVD
- Set the properties for the AVD
- Click create AVD
- Next, go to your application
- Right click on it and select "run as"
- go to run configuration
- now in the new window that opens up create a new configuration
- set the target device as the AVD that you just created
- Click apply
- Click Run.
Running application on a real Android Device:
First of all make sure that you install the drivers of your device on your PC.Then follow the following steps:
- Connect your device to your PC with the USB cable .
- Mount your android device.
- On your device go to settings>>Applications>>Development
- Enable USB debugging.
- Next, go to your application
- Right click on it and select "run as"
- go to run configuration
- now in the new window that opens up create a new configuration
- set the target
- select the radio button"Launch on all compatible devices/AVD"
- Select "active devices"
No comments:
Post a Comment