Empowering Creativity
In the next couple lessons, we will learn to create a simple android application consists of a splash screen, a button and with sound effects enabled. So, let’s started!
We are assuming that you have necessary tools installed, such as eclipse editor and Android SDK. If you haven’t already, please download all the tools at http://developer.android.com/sdk/index.html
We start the tutorial by creating an Android project using eclipse editor. Choosing File -> New Android Project, then insert all information as sown below:

Next, we will need to create a splash screen image and place it under the /res/drawable-mdpi folder. You can supply multiple densities of images for supporting multiple screens. But in this case, we just supply to medium dpi devices is enough.
Here is the image that we will use for the splash screen.

320px*480px
As you can see in the /res/layout folder, the “main.xml” is the default layout file automatically created when an Android project is created in eclipse. For this case, we will reserve this main.xml for our app’s main screen, which we will use it in the next lesson. So we will create a new layout named “splash.xml” for our splash screen. Do this by choosing File -> New -> Android XML File. Then insert the information as shown below:

Press finish button and you will see a new splash.xml file is place under /res/layout folder. Open the splash.xml and switch the view mode to “splash.xml” if your current xml view mode is switched to Graphical Layout. Then insert the splash screen image that we stored under /res/drawable-mdpi into the XML file using ImageView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/splash"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"/>
</LinearLayout>
Before we start to configure our app’s initial view, let’s talk about the activity life-cycle of an Android application. Following is the diagram that shows all statse of the entire lifetime of an activity.

onCreate() is fired when an app is started, so in this tutorial, we will setup all necessary resources in the onCreate() state.
If you want learn more about Activity, please log on to Android Developer Website.
Ok, let’s start to configure our splash screen. Do this by open up our “MainActivity.java” file which located in /src folder. Inside the onCreate() function, we change the “setContentView(R.layout.main)” to the following:
package com.tutorial.myapp;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
}
Save your code and run your code by choosing “Run -> Run”. Then an Android Virtual Device will launch and run the code that we just wrote. You will see our app showing the splash screen. You may wondering why the splash screen stop and hang there, this is because we haven’t tells Android what to shows after the splash screen!
So, let’s specify how long should we display the splash screen and what to show after next.

We will use a Thread to execute the duration of the visibility of splash screen. A thread is a concurrent unit of execution. Usually developer launch additional thread for specific purpose. Here is how we write a Thread to handle the duration of the splash screen:
package com.tutorial.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run(){
try{
int logoTimer = 0;
while(logoTimer < 5000){
sleep(100);
logoTimer = logoTimer +100;
};
startActivity(new Intent("com.tutorial.CLEARSCREEN"));
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
logoTimer.start();
}
}
Intent is just what it sound like, a way for us to declare to the Android system what you INTENT TO DO. This can be starting a specific activity, or it can be just asking Android system to find some program that can perform an action.
Next, we need to create a Java class to handle the app’s home screen. Do this by right click /src folder, “New -> Class”, and insert the following information:

Press “Finish” button, then you can see a new Java class is created and placed inside /src folder. Open it up and modify the code as same as below:
package com.tutorial.myapp;
import android.app.Activity;
import android.os.Bundle;
public class myMainScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
As you can see above, this class will look for “main.xml” and set it as its layout. We will insert more codes into this class for setting up the app’s home screen in the next lesson.
Lastly, we need to tells Android to start a new Activity based on the request named “CLEARSCREEN”, which we have specified in the “MainActivity.java” class. The AndroidManifest presents essential information about the application to the Android system, information the system must have before it can run any of the application’s code.
Let’s open up the AndroidManifest.xml and insert the following code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutorial.myapp"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".myMainScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.tutorial.CLEARSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Save your code and run in the Android Virtual Device (emulator). Here is our application running in the emulator.

In this tutorial, you’ve learned how to create a application consists of splash screen and other activities on the Android platform. You learn about Android App’s Activity, creating Java class, specifying XML layout in Java class and AndroidManifest.xml You’ve only scratched the surface of Android development. Remember to check out all the other great tutorials on onlyMobilePro.com to dive deeper into Android development.
Submitting Android Form Data Via POST Method