Wednesday 2 January 2013

My First Android Project


If you don't have an idea about the required software to create an android app, then visit my last post "Android Installation - SDK - AVD Manager"

To create first app and to grab the concept of android project, follow the steps mentioned below.

Just be with me....

Step 1: In Eclipse, Click on File --> New --> Project




Step 2: Android --> Android Application Project





Step 3: Here you need to provide lot many things.

  • Application Name: This name will be displayed, when an application is installed in device (For Example, Temple Run, Angry Bird)

  • Project Name: It's like a temporary Name. Project name will be displayed, as the name of project that we create in Eclipse. You can name it anything (may be same as Application Name).

  • Package Name: Here you need to be, bit careful. Every app in the play-store has a different package name. Keep two things in mind while providing package name. First, it has to be unique and the second, there must be one dot (.) in the package name.

  • Minimum Required SDK: Choose the lowest version of android that your application will support. Always prefer API level 8 to reach approximately 95% of the market.

  • Target SDK: Choose the Target Version, against which you want to test your application. You can prefer to latest version.
  • Compile With: Choose a target API to compile your code against, from your installed SDK. Always choose the highest API level.
  • Theme: Select a theme for your application.






Step 4: If you want to create an activity and choose your own launcher icon, then don't change the default selection. This project will be saved in workspace; you can change location, if you want. Now, Click on "Next" button.






Step 5: There are three options that android provides to set your Launcher Icon. You can keep an image of your own choice, by clicking on browser button.




The second choice is to set Clipart as your Icon. Click on choose button, where you find lot many Clip Art. You can select one of them.







The third or the last option is to keep text as your icon. Type whatever you would like as Text and then choose Font.






After selecting any of them, click on the Next button.



Step 6: You have five different choices to create an activity.

  • BlankActivity: Just creates a simple blank activity.
  • FullscreenActivity: Creates a new activity that shows and hides the system UI(status bar, system bar), and action bar, upon user interaction.
  • LoginActiity: Creates a new login activity, allowing users to enter a username / email address and password to login or register for your service.
  • MasterDetailFlow: This activity requires a minimum SDK version of at least 11. This master/detail flow activity creates two columns on tablets.
  • SettingActivity: Creates a new application settings activity.




Just choose the BlankActivity and click on Next button.


Step 7: Now, the last step of creating project.

  • Activity Name: The name of the Activity class to create.
  • Layout Name: The name of the layout to create for the activity.
  • Navigation Type: Choose the navigation type for your activity. The minimum SDK version has to be at least 11 to choose any of the navigation Type. So keep it "None" and click on Finish button.



Half Job is done now....


Once the project is created, it looks as shown below. We can see all files and folders of project in the "Project Explorer". The Graphical Layout of xml file (activity_myapp.xml) shows, how the default activity looks.






Apart from layout xml file, there are two other files that we have most interaction with.

(1) Java File in src folder
(2) strings.xml file in values folder.


MyApp.java

All the classes (or java file) of project are created in the src folder. Now, double click on the MyApp.java file to view it.





Strings.xml

Android allows you to create static attributes, e.g. Strings / Arrays / Colors. These attributes can be used in XML layout files or referred via Java Source Code. Open the res/values/string.xml file in Eclipse.






Click on Add button. Select String element and press ok button.





Type "display_info" in Name attribute and "This Is My First App" in Value attribute. The same way, add two more attributes here.

Name
Value
editText_info
Type Something Here
Btn_info
Cool


Switch to XML representation and check that the values are correct. We will use these attributes in layout xml file.
















activity_myapp.xml

You have seen the default view of this xml file. Now, I am going to add some UI components in xml file. We can change the layout by drag and drop or editing the XML source code. You can switch between them anytime. Screenshot of Palette is shown here.





From Palette, drag & drop one Button and EditText into the layout.

Switch Graphical Layout to the XML file and compare your code, with the code shown below. If code is not same, then modify it.



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyApp" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="71dp"
        android:ems="10"
        android:inputType="text"
        android:text="@string/editText_info"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="76dp"
        android:text="@string/display_info"
        android:textSize="20sp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/btn_info" />

</RelativeLayout>



If you have done job correctly, then your Graphical layout should look as this.





AndroidManifest.xml

Now, have a look over the most important file (AndroidManifest.xml) of project. You can consider it, as the controller of whole application. All Permissions, Activities, Services, and much other important information are described in this file.








Test Your APP:

To test your app; right click on the project, click on Run As --> Android Application, OR just press F11 to run your Application. However, if you have created multiple AVD of different SDK version then you can choose specific one.

To do that, right click on the project, choose Run As --> Run Configuration. This will open new window.

In Target tab of window, choose any AVD you like and then press Run button.




So, it's done now........

Output:










Enjoy....


13 comments:

  1. Thanks Very Much!

    ReplyDelete
  2. Thank you very much, It is very helpful for beginners.:)

    ReplyDelete
  3. Thanks, Big help. I am new to android development and had hard time how to start the so called. "Project Files".

    ReplyDelete
  4. Congratulations guys, quality information you have given!!!..Its really useful blog. Thanks for sharing this useful information
    Android Training in chennai | Android Training|Android Training in chennai with placement | Android Training in velachery

    ReplyDelete
  5. Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, anyways I am here now and would just like to say thanks for a tremendous post. Please do keep up the great work.
    Authorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai

    ReplyDelete
  6. I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts.

    Looking for Big Data Hadoop Training Institute

    in Bangalore
    , India. Prwatech is the best one to offers computer training courses including IT software course in Bangalore, India.

    Also it provides placement assistance service in Bangalore for IT. Best Data Science Certification Course in Bangalore.

    Some training courses we offered are:

    Big Data Training In Bangalore
    big data training institute in btm
    hadoop training in btm layout
    Best Python Training in BTM Layout
    Data science training in btm
    R Programming Training Institute in Bangalore
    apache spark training in bangalore
    Best tableau training institutes in Bangalore
    data science training institutes in bangalore
    Hadoop

    Training Institute In Bangalore

    ReplyDelete
  7. This article is really helpful for me. I am regular visitor to this blog. Share such kind of article more in future. Personally i like this article a lot and you can have a look at my services also: I was seriously search for a Salesforce training institutes in ameerpet which offer job assistance and Salesforce training institutes in Hyderabad who are providing certification material. It's worth to join Salesforce training institutes in India because of their real time projects material and 24x7 support from customer desk. You can easily find the best Salesforce training institutes in kukatpally kphb which are also a part of Pega training institutes in hyderabad. This is amazing to join Data science training institutes in ameerpet who are quire popular with Selenium training institutes in ameerpet and trending coureses like Java training institutes in ameerpet and data science related programming coures python training institutes in ameerpet If you want HCM course then this workday training institutes in ameerpet is best for you to get job on workday.

    ReplyDelete
  8. Great Post! Thanks for sharing. Keep sharing such information.

    Apply Now for Android Training in Noida

    For more details about the course fee, duration, classes, certification, and placement call our expert at 70-70-90-50-90

    ReplyDelete
  9. Embarking on your first Android project is a significant milestone. It's a journey of creativity, learning, and problem-solving. Top Permanently Games Embrace the challenges, relish the small victories.

    ReplyDelete