Introduction To Google Android (Ft Rohan Bomle)

5,256 views

Published on

Introduction to basic of Google Android Application Development.

Published in: Technology
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total views
5,256
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
438
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Introduction To Google Android (Ft Rohan Bomle)

  1. 1. Google Android<br />Fafadia Tech<br />RohanBomle(rohan@fafadia-tech.com)<br />
  2. 2. Android<br />What is Android?<br /><ul><li>A software platform and operating system for mobile devices
  3. 3. Based on the Linux kernel
  4. 4. Developed by Google and later the Open Handset Alliance (OHA)
  5. 5. Allows writing managed code in the Java language
  6. 6. C/C++ also possible but not supported</li></li></ul><li>IDE and Tools<br />Android SDK<br /><ul><li>Class Library
  7. 7. Developer Tools
  8. 8. dx – Dalvik Cross-Assembler
  9. 9. aapt – Android Asset Packaging Tool
  10. 10. adb – Android Debug Bridge
  11. 11. ddms – Dalvik Debug Monitor Service
  12. 12. Emulator and System Images
  13. 13. Documentation and Sample Code</li></ul>Eclipse IDE + ADT (Android Development Tools)<br /><ul><li>Reduces Development and Testing Time
  14. 14. Makes User Interface-Creation easier
  15. 15. Makes Application Description Easier</li></li></ul><li>How to install ADT in Eclipse<br />Start Eclipse, then select Help > Software Updates > Find and Install.... In the resulting dialog box, enter a name for the remote site (e.g. Android Plugin) and enter this as its URL: https://dl-ssl.google.com/android/eclipse/. Press OK.<br />You should now see the new site added to the search list (and checked). Press Finish.In the subsequent Search Results dialog box, select the checkbox for Android Plugin > Eclipse Integration > Android Development Tools and press Next.<br />Read the license agreement and then select Accept terms of the license agreement, if appropriate. Press Next. Press Finish.The ADT plugin is not signed; you can accept the installation anyway by pressing Install All. Restart Eclipse. <br />
  16. 16. Android applications have common structure<br />Activity is the presentation layer of your app: there will be one per screen, and the Views provide the UI to the activity<br />Intents specify what specific action should be performed<br />Services run in the background and have no UI for the user – they will update data, and trigger events<br />
  17. 17. There is a common file structure for applications<br />code<br />Autogenerated resource list<br />files<br />images<br />UI layouts<br />constants<br />
  18. 18. Standard components form building blocks for Android apps<br />Notifications<br />Has life-cycle<br />Activity<br />screen<br />Views<br />App to handle content<br />Intents<br />Background app<br />Like music player<br />Service<br />manifest<br />ContentProviders<br />Other applications<br />
  19. 19. Simple Android Application (java program)<br />package com.google.android.helloactivity;<br />import android.app.Activity;<br />import android.os.Bundle;<br />public class HelloActivity extends Activity {<br /> public HelloActivity() {<br /> }<br /> @Override<br /> public void onCreate(Bundle icicle) {<br />super.onCreate(icicle);<br />setContentView(R.layout.hello_activity);<br /> }<br />}<br />
  20. 20. The AndroidManifest lists application details<br /><?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://schemas.android.com/apk/res/android"<br /> package="com.my_domain.app.helloactivity"><br /> <application android:label="@string/app_name"><br /> <activity android:name=".HelloActivity"><br /> <intent-filter><br /> <action android:name="android.intent.action.MAIN"/><br /> <category android:name="android.intent.category.LAUNCHER"/><br /> </intent-filter><br /> </activity><br /> </application><br />
  21. 21. main.xml <br /><?xml version="1.0" encoding="utf-8"?><br /><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"<br />android:layout_width="fill_parent"<br />android:layout_height="fill_parent"<br />android:background="#000044"><br /><TextView<br />android:layout_width="fill_parent" <br />android:layout_height="wrap_content" <br />android:text="@string/hello"<br />/><br /></LinearLayout><br />
  22. 22. Creating and Running simple HelloWorld application<br />To create a new project:<br /> 1. Start Eclipse<br /> 2. Select File > New > Project.<br /> 3. Select Android > Android Project,<br /> and click Next.<br /> 4. Enter Project name: HelloWorld.<br /> 5. Select Target Android 1.5.<br /> 6. Application name: Hello.<br /> 7. Package name: fafadia.tech.<br /> 8. Create Activity: HelloWorld.<br /> 9. Min SDK Version: 3.<br /> 10. Click Finish.<br />
  23. 23. Creating HelloWorld.java<br />package matos.demo;<br />import android.app.Activity;<br />import android.widget.Toast;<br />public class HelloWorldextends Activity {<br /> /** Called when the activity is first created. */<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />setContentView(R.layout.main);<br />Toast.makeText(getBaseContext(),“Wlecome to Hello World”,Toast.LENGTH_SHORT).show();<br /> }<br />}<br />
  24. 24. Run HelloWorld application<br />To run android application<br /> 1.Run <br /> 2.Run > Select Android Application<br /> 3. Press ok<br />
  25. 25. Adding more UI components to your application<br />There are to ways to add your UI components<br />Through coding (java code)<br />Or defining in main.xml<br />Xml code<br />Java code<br />TextViewtv = new TextView();<br />Tv.setText(“Hello”);<br /><TextViewandroid:layout_width="fill_parent" <br />android:layout_height="wrap_content" <br />android:text="@string/hello"<br /> /><br />
  26. 26. Lets create a same application with UI components<br />package org.HelloWorld.com;<br />import android.app.Activity;<br />import android.os.Bundle;<br />import android.widget.LinearLayout;<br />import android.widget.ScrollView;<br />public class HelloWorld extends Activity {<br />public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />// setContentView(R.layout.main);<br />ScrollViewsv = new ScrollView(this);<br />LinearLayoutll = new LinearLayout(this);<br />ll.setOrientation(LinearLayout.VERTICAL);<br />sv.addView(ll);<br />this.setContentView(sv);<br /> }<br />}<br />
  27. 27. Adding components to Layout<br />final TextViewtv = new TextView(this);<br />tv.setText(“Text Box");<br />tv.setTextSize(20);<br />tv.setTextColor(Color.BLACK);<br />ll.addView(tv);<br />Button b1 = new Button(this);<br /> b1.setText("Submit");<br /> b1.setTextSize(15);<br />ll.addView(b1);<br /> b1.setOnClickListener(new View.OnClickListener() {<br /> public void onClick(View v)<br /> {<br />tv.setText(“Submit button Clicked”);<br /> });<br />
  28. 28.
  29. 29. Creating simple database application<br />First we create a simple class which create a database, table. And the we perform insert and select query on table.<br />Android uses SQLite for its database needs. SQLite is a very fast and lightweight database.<br />Create New Project as MYDatabase and in that create new file named it as create_database.java.<br />Import two files <br /> import android.database.Cursor;<br />importandroid.database.sqlite.SQLiteDatabase;<br />
  30. 30. Create_database file<br />package org.example.mydatabase;<br />import android.app.Activity;<br />import android.database.Cursor;<br />import android.database.sqlite.SQLiteDatabase;<br />import android.os.Bundle;<br />import android.util.Log;<br />import android.widget.TextView;<br />public class create_database extends Activity {<br /> public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />setContentView(R.layout.main);<br />super.onCreate(savedInstanceState);<br />SQLiteDatabasemyDB= null;<br /> String TableName = "myTable";<br /> String Data="";<br />
  31. 31. /* Create a Database. */<br /> try <br /> {<br />myDB = this.openOrCreateDatabase("DatabaseName", MODE_PRIVATE, null);<br /> /* Create a Table in the Database. */<br />myDB.execSQL("CREATE TABLE IF NOT EXISTS “+ TableName<br /> + " (Field1 VARCHAR, Field2 INT(3));");<br /> /* Insert data to a Table*/<br />myDB.execSQL("INSERT INTO “ + TableName+ " (Field1, Field2)"<br /> + " VALUES ('katrina', 25);");<br /> /*retrieve data from database */<br /> Cursor c = myDB.rawQuery("SELECT * FROM " + TableName , null);<br />int Column1 = c.getColumnIndex("Field1");<br />int Column2 = c.getColumnIndex("Field2");<br /> // Check if our result was valid.<br />c.moveToFirst();<br />
  32. 32. if (c != null) <br />{ // Loop through all Results<br /> do <br /> {<br /> String Name = c.getString(Column1);<br />int Age = c.getInt(Column2);<br /> Data =Data +Name+"/"+Age+" ";<br /> }while(c.moveToNext());<br />}<br />TextViewtv = new TextView(this);<br />tv.setText(Data);<br />setContentView(tv); <br />}//end try<br />catch(Exception e) <br /> { System.out.println("Error", "Error", e);} <br /> finally { if (myDB != null) myDB.close(); }<br /> }<br />}<br />
  33. 33.
  34. 34. Thank You<br />

×