Android DevelopmentTraining for BeginnersFIRST DAY MODULE            By: Joemarie Comeros Amparo
Outline:   Overview on Android   Installing ADT on Eclipse   Explore Project Components   Sample Android Project   Ru...
Android is an open mobile phone platform that was   developed by Google and later by Open Handset   Alliance. Google defin...
July 2005 - Google Inc. bought from Danger Inc.Open Handset Alliance was formed headed by Google  which is composed of com...
   Android   1.1   Android   1.5 Cupcake   Android   1.6 Donut   Android   2.0/2.1 Eclair   Android   2.2.x Froyo   ...
Note: When developing an application, consider the market share of the android version. Thehigher the market share, the hi...
Note: Based on my development experience, ADT can run on at least Dual Core with atleast 2GB RAM.
Please refer to:       www.developershaven.net
Activity• Present a visual user interface for one focused endeavor the user can undertake• Example: a list of menu items u...
public class CCSActivity extends Activity{   @Override   public void onCreate(Bundle                 savedInstanceState)  ...
   Run in the background     Can continue even if Activity that started it dies     Should be used if something needs t...
SRC• The project source codeGEN• Auto generated code• Example: R.javaIncluded librariesResources• Drawables• Layout• Value...
   Auto-generated: YOUR SHOULD’NT EDIT IT!   Contains IDs of the project resources   Enforces good software engineering...
   Eclipse has a great UI creator       Generates the XML for you   Composed of View objects   Can be specified for po...
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"   android:la...
1. Lunching a new activity without expecting without expecting a result2. Lunching a new activity and expecting a result w...
   On Eclipse IDE. Go To File >    New > Project > Android    Project   See image at the side for the    prompt that app...
   Select android version.    Tip: select the latest OS    version available. You can    add minimum and target SDK    on...
   Provide package name of    your project. Valid package    name consist of two names    separated by a period.
   Provide package name of    your project. Valid package    name consist of two names    separated by a period.   Optio...
In main.xml:   Under res/layout on your    <?xml version="1.0" encoding="utf-8"?>                                <LinearL...
    Under res/values on your     project explorer. Open     strings.xml.<?xml version="1.0" encoding="utf-8"?><resources>...
    Under SRC on your project       public class SampleProjectActivity extends Activity implements OnClickListener{      ...
   Create NextActivity.java       import android.app.Activity;                                   import android.os.Bundle...
   Open Manifest.xml in your        <?xml version="1.0" encoding="utf-8"?>    project explorer.                <manifest ...
   Right click your project name in your project explorer > RUN AS    > ANDROID APPLICATION.   Emulator will boot up. Wa...
   Installation: http://developershaven.net   Google API: http://mfarhan133.wordpress.com/2010/10/01/generate-google-map...
Joemarie Comeros Amparo               about.me/joemarieamparo      Skype/Ymail/Gmail : joemarieamparo     Facebook: joemar...
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
Upcoming SlideShare
Loading in...5
×

Android Development for Beginners with Sample Project - Day 1

23,964

Published on

This for CCA Java Class Batch 4 Android Development Training for Beginners.

0 Comments
22 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
23,964
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
1,210
Comments
0
Likes
22
Embeds 0
No embeds

No notes for slide

Android Development for Beginners with Sample Project - Day 1

  1. 1. Android DevelopmentTraining for BeginnersFIRST DAY MODULE By: Joemarie Comeros Amparo
  2. 2. Outline: Overview on Android Installing ADT on Eclipse Explore Project Components Sample Android Project Running Android Project
  3. 3. Android is an open mobile phone platform that was developed by Google and later by Open Handset Alliance. Google defines Android as a "software stack" for mobile phones.Software stack is made up of operating system(the platform on which everything runs), the middleware (the programming that allows applications to talk to a network and to one another) and the applications (the actual programs that phone will run)
  4. 4. July 2005 - Google Inc. bought from Danger Inc.Open Handset Alliance was formed headed by Google which is composed of companies like Intel, T- Mobile, Spring Nextel and more.In 2008, Android became available as an open source and ASOP(Android Open Source Project) is responsible for maintaining and development of android.February 2009, the first android version was released, Android 1.1. for Mobile G1.
  5. 5.  Android 1.1 Android 1.5 Cupcake Android 1.6 Donut Android 2.0/2.1 Eclair Android 2.2.x Froyo Android 2.3.x Gingerbread Android 3. x Honeycomb Android 4.0.x Ice Cream Sandwich Android 4.1 Jelly Bean
  6. 6. Note: When developing an application, consider the market share of the android version. Thehigher the market share, the higher number your target market is.
  7. 7. Note: Based on my development experience, ADT can run on at least Dual Core with atleast 2GB RAM.
  8. 8. Please refer to: www.developershaven.net
  9. 9. Activity• Present a visual user interface for one focused endeavor the user can undertake• Example: a list of menu items users can choose from Services• Run in the background for an indefinite period of time• Example: calculate and provide the result to activities that need it Broadcast Receivers• Receive and react to broadcast announcements• Example: announcements that the time zone has changed Content Providers• Store and retrieve data and make it accessible to all applications• Example: Android ships with a number of content providers for common Intents• Hold the content of a message• Example: convey a request for an activity to present an image to the user or let the user edit some text
  10. 10. public class CCSActivity extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }}
  11. 11.  Run in the background  Can continue even if Activity that started it dies  Should be used if something needs to be done while the user is not interacting with application  Otherwise, a thread is probably more applicable  Should create a new thread in the service to do work in, since the service runs in the main thread Can be bound to an application  In which case will terminate when all applications bound to it unbind  Allows multiple applications to communicate with it via a common interface Needs to be declared in manifest file Like Activities, has a structured life cycle
  12. 12. SRC• The project source codeGEN• Auto generated code• Example: R.javaIncluded librariesResources• Drawables• Layout• Values like stringsManifest File• A must have xml file. Contains essential information about the system to the android system
  13. 13.  Auto-generated: YOUR SHOULD’NT EDIT IT! Contains IDs of the project resources Enforces good software engineering Use findViewById and Resources object to get access to the resources  Ex. Button b = (Button)findViewById(R.id.button1)  Ex. getResources().getString(R.string.hello));
  14. 14.  Eclipse has a great UI creator  Generates the XML for you Composed of View objects Can be specified for portrait and landscape mode  Use same file name, so can make completely different UIs for the orientations without modifying any code
  15. 15. <?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:id="@+id/tv_hello"/> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Large Text“android:textAppearance="?android:attr/textApp res/values/string.xmlearanceLarge"/></LinearLayout>
  16. 16. 1. Lunching a new activity without expecting without expecting a result2. Lunching a new activity and expecting a result when it finished.CalledActivity.class
  17. 17.  On Eclipse IDE. Go To File > New > Project > Android Project See image at the side for the prompt that appear. Click next button.
  18. 18.  Select android version. Tip: select the latest OS version available. You can add minimum and target SDK on your manifest file to support earlier android versions.
  19. 19.  Provide package name of your project. Valid package name consist of two names separated by a period.
  20. 20.  Provide package name of your project. Valid package name consist of two names separated by a period. Optional: Change minimum SDK for the lowest android version your application will support. Hit on finish
  21. 21. In main.xml: Under res/layout on your <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" project explorer. Open android:layout_width="fill_parent" android:layout_height="fill_parent" main.xml. Create a layout android:orientation="vertical" > <TextView like this: android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 3" /> </LinearLayout> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > <requestFocus /> </EditText> </LinearLayout>
  22. 22.  Under res/values on your project explorer. Open strings.xml.<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, SampleProjectActivity!</string> <string name="app_name">SampleProject</string> <string name="button1">Button 1 Clicked.</string></resources>NOTE: string with name button1 is being referenced by Button 1 android:text property.See main.xml in your layout.
  23. 23.  Under SRC on your project public class SampleProjectActivity extends Activity implements OnClickListener{ /** Called when the activity is first created. */ explorer. Open @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SampleProjectActivity.java. setContentView(R.layout.main); Toast.makeText(this, "Hello.", Toast.LENGTH_LONG).show(); //referencing components in our layout as set in setContentView, - main.xml //findViewById is used hence we components in our layout will be called Change code to this: //through their ids as set in android:id properties. See main.xml in your layout. Button btn1 = (Button)findViewById(R.id.button1); //one way in handling click event btn1.setOnClickListener(new View.OnClickListener() { See comments for better @Override public void onClick(View v) { //Toast is a prompt that will notify user of what has happened in the understand. application //but not requiring user an action. Toast.makeText(getApplication(), "Button 1 Clicked", Toast.LENGTH_LONG).show(); } });import android.app.Activity; Button btn2 = (Button)findViewById(R.id.button2); Button btn3 = (Button)findViewById(R.id.button3);import android.content.Intent; //Other way of handling event inside an activity btn2.setOnClickListener(this);import android.os.Bundle; } btn3.setOnClickListener(this);import android.view.View; @Override public void onClick(View v) {import // TODO Auto-generated method stubandroid.view.View.OnClickListener; switch(v.getId()) { case R.id.button2:import android.widget.Button; EditText editText = (EditText)findViewById(R.id.editText1); editText.setText("Button 2 Clicked!");import android.widget.EditText; break; case R.id.button3: // Intent with out waiting for result.import android.widget.Toast; // This is creating a new view and passing the new controll to the next view. Intent intent = new Intent(this, NextActivity.class); startActivity(intent); break; } } }
  24. 24.  Create NextActivity.java import android.app.Activity; import android.os.Bundle; Right click SRC folder > New import android.widget.Button; import android.widget.TextView; > Class. public class NextActivity extends Activity{ Change code to this: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // you can have a new layout. but for this example // we will be reusing the main.xml as our layout. // we will just manipulate the text to inform user that //a new activity has been created. setContentView(R.layout.main); // setTitle - change the title of the next view setTitle("Next Activity"); //setting page title TextView pageTitle = (TextView)findViewById(R.id.pagetitle); pageTitle.setText("Hello, You are now in the Next Activity Class."); Button btn1 = (Button)findViewById(R.id.button1); btn1.setText("Option 1"); Button btn2 = (Button)findViewById(R.id.button2); btn2.setText("Option 2"); Button btn3 = (Button)findViewById(R.id.button3); btn3.setText("Option 3"); } }
  25. 25.  Open Manifest.xml in your <?xml version="1.0" encoding="utf-8"?> project explorer. <manifest xmlns:android="http://schemas.android.com/apk/re s/android" Register NextActivity class to package="com.sample" android:versionCode="1" your project. android:versionName="1.0" > Your new manifest file must <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/> look like the code at the <application android:icon="@drawable/ic_launcher" side. android:label="@string/app_name" > <activity Save all the changes android:name=".SampleBradActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHE R" /> </intent-filter> </activity> <activity android:name=".NextActivity" android:label="@string/app_name" /> </application> </manifest>
  26. 26.  Right click your project name in your project explorer > RUN AS > ANDROID APPLICATION. Emulator will boot up. Wait until home screen is shown. Your application will be displayed on the screen. You can now enjoy the application. Congratulations!!!
  27. 27.  Installation: http://developershaven.net Google API: http://mfarhan133.wordpress.com/2010/10/01/generate-google-maps-api-key-for-android/ Android Developer’s Website : http://developer.android.com/index.html Numerous Forums & other developer sites, including:  http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html  http://efreedom.com/Question/1-6070968/Google-Maps-Api-Directions  http://stackoverflow.com  http://www.anddev.org/google_driving_directions_-_mapview_overlayed-t826.html
  28. 28. Joemarie Comeros Amparo about.me/joemarieamparo Skype/Ymail/Gmail : joemarieamparo Facebook: joemarieamparo@yahoo.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×