Friday 1 February 2013

Creating the Splash Screen


package com.QDRoid.Database;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Splash extends Activity {
 @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.splash);
       Handler x=new Handler();
       x.postDelayed(new splashHandler(), 2000);
   }
   public class splashHandler implements Runnable {

    public void run() {
    // TODO Auto-generated method stub
   
    startActivity(new Intent(getApplication(),Menu.class));
    Splash.this.finish();
    }

   }
}

Thursday 10 January 2013

My Book

Hey Guys !!

Sorry to all those who have been waiting for posts on this blog. Recently I have received many requests for help regarding Android Development. Somehow due to my busy schedule at work I have not been able to help you guys and I am extremely sorry for that. But after all this time I am back with my new Year resolution of writing my blog regularly and also for being available to you guys .And trust me this time I am not going to let you down.This time I also have have great piece of news for you that I have just completed my manuscript for my book which is about learning android Development right from the scratch. This book basically targets the beginners. It consists of of not only the source code but also the various artifacts which is an essential part of the object oriented development of the software , I hope that the books would be available to you guys by this month end, if everything goes well ... amen !!! :) Looking forward to your feedback and responses.. and I hope that they would be positive. :) .

Sunday 11 November 2012

Handling the activity not Launched Problem

While  creating the application we add new Activities and corresponding to that we have to add the reference to the activity in the AndroidManifest.xml file but there is another important step that needs to be taken into account in order to launch or start a new activity on the emulator.

This deals with adding the Intent - which does the binding of the various components and the functionalties  related to them at the run time.  This can be done between the components of the same or different package.

So we need to write the following code in the Manifest file :
<application
.............
.............
<activity
.............
.............

 <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
</activity>
</application>

Without the above line the application does not gets launched on the emulator.

Now let's understand what the above lines mean in effect:


  • Intent-filter - By this we implicitly define that to which intent the component is to be bound at the run time and we filter out the rest undesirable intents.
    • category android:name="android.intent.category.LAUNCHER" : we specify that we want to be able to launch this specific activity.

Handling The android.content.ActivityNotFoundException: Unable to find explicit activity class


ActivityNotFoundException is the most common exception encountered while developing the android application. This can be compared to the class not found exception. We will see why this exception arises and how to deal with it.

Reason 1: Class Reference Not Mentioned in the AndroidManifest.xml  file
All the activities of our package must be mentioned in the manifest file otherwise the debugging of the application can not be done.This is done by adding the reference to the activity within the <activity></activity> tags .
Solution: Add the reference to the class in the manifest file by simply writing :

<activity android:name=".YourActivityName"></activity>

Reason 2: Syntax Error or Wrong Package Name Mentioned while Starting the New Activity
The correct naming of the package is important. Being a syntactical error this is not so dangerous.

Solution: Check the Package Name and write the following code for launching the new Activity

Intent launchNewIntent = new Intent(CurrentActivity.this,NewActivity.class);
    startActivityForResult(launchNewIntent, 0);


 Reason 3: Updates Not Installed: 
sometimes even if you have done all the coding correctly you still encounter this Exception.

Solution : Go to Help--->> Check For Updates---->>Install Updates(if you are prompted to install new updates)---->>Restart eclipse --->>Run your application again

Friday 24 August 2012

Pleasant Surprise : Android SDK Tools Revision 20

Breath of fresher air for the developers the SDK tools revision 20 is finally here .

You can either download a fresh or upgrade the existing SDK tools to the revision 20.The  revision 20.0 came in June this year and was followed by the revision 20.0.1 release in July and revision 20.0.3 release in August with the bug fixes. 
Using the SDK R20 requires use to be used with ADT of the same revision in Eclipse which means that if you wish to use the SDK R20.0.3 you must use it with the ADT revision 20.0.3 in the Eclipse IDE.Otherwise Apche Ant 1.8 or + could be used outside the Eclipse IDE.

Upgrading the ADT plugin the Eclipse IDE  if you already have ADT plugin installed in the Eclipse IDE that you use for the development purposes, you can easily upgrade the it by just:
  • Go to help
  • Select Check for updates
  • Select DDMS, ADT etc updates 
  • click next
  • click next again 
  • Accept the License agreement 
  • click finish
  • for changes to to actually take place , Restart Eclipse.




Now get ready to use the new and exciting SDK tools with the ADT which offers such ease to chose the templates for creating beautiful looking application at the click of a button .

Friday 27 July 2012

Running the Android Application

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:

  • 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:

  1. Go to window in the Eclipse IDE
  2. Select AVD manager
  3. create new AVD
  4. Set the properties for the AVD
  5. Click create AVD
  6. Next, go to your application 
  7. Right click on it and select "run as"
  8. go to run configuration
  9. now in the new window that opens up create a new configuration 
  10. set the target device as the AVD that you just created 
  11. Click apply
  12. 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:
  1. Connect your device to your PC with the USB cable .
  2. Mount your android device.
  3. On your device go to settings>>Applications>>Development
  4. Enable USB debugging.
  5. Next, go to your application 
  6. Right click on it and select "run as"
  7. go to run configuration
  8. now in the new window that opens up create a new configuration 
  9. set the target
  10. select the radio button"Launch on all compatible devices/AVD"
  11. Select "active devices"

Monday 23 July 2012

Creating A Beautiful Samsung Nexus S AVD

Bored with the traditional android AVD I wanted to run my programs in the new screen so I tried the new Samsung Nexus S skin .

If you wish to do the same just do the following steps and you'll be done :


  • Download the NEXUS-S skin from here
  • Unzip the file and locate it the "platforms" folder inside the android SDK folder 
  • Inside the platforms folder you will find  a folder for Skin 
  • Paste the unzipped NEXUS-S file into the skin folder 
  • Now go to eclipse
  • windows>> AVD manager 
  • click new to create a new AVD
  • Now you select the NEXUS-S skin 

now we are good to go and run our application on the new NEXSUS-S skin :)




My Tutube video for the same: