Android Dr. Vaishali D. Khairnar IT Department

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Android architecture overview
Android Platform Overview (1)
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Mobile Application Development
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
Introduction to Android Platform Overview
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Android Introduction Platform Overview.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
Android Introduction Based on slides made by
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
01. Introduction to Android Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea
Social Media Apps Programming Min-Yuh Day, Ph.D. Assistant Professor Department of Information Management Tamkang University
Android for Java Developers Denver Java Users Group Jan 11, Mike
Android - Broadcast Receivers
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Creating an Example Android App in Android Studio Activity lifecycle & UI Resources.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
ANDROID BY:-AANCHAL MEHTA MNW-880-2K11. Introduction to Android Open software platform for mobile development A complete stack – OS, Middleware, Applications.
Created By. Jainik B Patel Prashant A Goswami Gujarat Vidyapith Computer Department Ahmedabad.
1 Android Introduction Platform Overview. 2 What is Android?  Android is a software stack for mobile devices that includes an operating system, middleware.
Lecture 2: Android Concepts
1 Android Workshop Platform Overview. 2 What is Android?  Android is a software stack for mobile devices that includes an operating system, middleware.
J.BHAVANA 3/4B.TECH CSE Ch.Rochasmathi 3/4B.tech CSE.
By Adam Reimel. Outline Introduction Platform Architecture Future Conclusion.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Programming.
Android Mobile Application Development
Lab7 – Appendix.
Introduction to android
Android Application -Architecture.
Lecture 2: Android Concepts
Mobile Application Development BSCS-7 Lecture # 2
Visit for more Learning Resources
ANDROID AN OPEN HANDSET ALLIANCE PROJECT
Activities, Fragments, and Events
Android.
MAD.
Activities and Intents
Android Mobile Application Development
CMPE419 Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Application Development A Tutorial Driven Course
CMPE419 Mobile Application Development
Activities and Intents
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Introduction Platform Mihail L. Sichitiu.
Android Platform, Android App Basic Components
Introduction to Android
Lecture 2: Android Concepts
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Android Dr. Vaishali D. Khairnar IT Department Terna Engineering College

What is Android? Android is a software stack for mobile devices that includes an operating system, middleware and key applications.

OHA (Open Handset Alliance) A business alliance consisting of 47 companies to develop open standards for mobile devices

Phones HTC G1, Droid, Tattoo Motorola Droid (X) Sony Ericsson Suno S880 Samsung Galaxy

Tablets Velocity Micro Cruz Gome FlyTouch Acer beTouch Toshiba Android SmartBook Cisco Android Tablet Dawa D7

Android Studio Installation Steps Step 1: System Requirements Microsoft® Windows® 8/7/Vista/2003 (32 or 64-bit) Java JDK5 or later version (jdk1.8.0_101) Java Runtime Environment (JRE) or later version (jre1.8.0_101) Set-up Java Development Kit (JDK) set JAVA_HOME=C:\jdk1.8.0_101 Android Studio (android-studio-bundle-143.3101438-windows.exe) Android Studio is the official IDE for android application development. It works based onIntelliJ IDEA Link for Android Studio developer.android.com/sdk/index.html

launch Android Studio.exe Machine should required installed Java JDK. Step 2: Installation launch Android Studio.exe Machine should required installed Java JDK. By clicking on next complete the wizard for Android Studio. Errors JDK error Install latest version of jdk and configure it. HAXM installation failed. Download HAXM from link https://software.intel.com/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-windows (haxm-windows_v6_0_3.zip) Extra it and run (intelhaxm-android.exe and haxm_check.exe)

Hello Word Example App>res>layout>Activity_main.xml

Architecture

Android S/W Stack - Application Android provides a set of core applications: Email Client SMS Program Calendar Maps Browser Contacts Etc All applications are written using the Java language.

Application components are the essential building blocks of an Android application. These components are loosely coupled by the application manifest file AndroidManifest.xml that describes each component of the application and how they interact. Components Description Activities They dictate the UI and handle the user interaction to the smart phone screen Services They handle background processing associated with an application. Broadcast Receivers They handle communication between Android OS and applications. Content Providers They handle data and database management issues.

Additional Components: used in the construction of above mentioned entities, their logic, and wiring between them etc. Components Description Fragments Represents a portion of user interface in an Activity. Views UI elements that are drawn on-screen including buttons, lists forms etc. Layouts View hierarchies that control screen format and appearance of the views. Intents Messages wiring components together. Resources External elements, such as strings, constants and drawable pictures. Manifest Configuration file for the application.

Android S/W Stack – App Framework Enabling and simplifying the reuse of components Developers have full access to the same framework APIs used by the core applications. Users are allowed to replace components.

Android S/W Stack – App Framework (Cont) Features Feature Role View System Used to build an application, including lists, grids, text boxes, buttons, and embedded web browser Content Provider Enabling applications to access data from other applications or to share their own data Resource Manager Providing access to non-code resources (localized strings, graphics, and layout files) Notification Manager Enabling all applications to display customer alerts in the status bar Activity Managing the lifecycle of applications and providing a common navigation backstack

Android S/W Stack - Libraries Including a set of C/C++ libraries used by components of the Android system Exposed to developers through the Android application framework

Android S/W Stack - Runtime Core Libraries Providing most of the functionality available in the core libraries of the Java language APIs Data Structures Utilities File Access Network Access Graphics Etc

Android S/W Stack – Runtime (Cont) Dalvik Virtual Machine Providing environment on which every Android application runs Each Android application runs in its own process, with its own instance of the Dalvik VM. Dalvik has been written such that a device can run multiple VMs efficiently. Register-based virtual machine

Android S/W Stack – Runtime (Cont) Dalvik Virtual Machine (Cont) Executing the Dalvik Executable (.dex) format .dex format is optimized for minimal memory footprint. Compilation Relying on the Linux Kernel for: Threading Low-level memory management

Android S/W Stack – Linux Kernel Relying on Linux Kernel 2.6 for core system services Memory and Process Management Network Stack Driver Model Security Providing an abstraction layer between the H/W and the rest of the S/W stack

Create Android Application (HelloWorld) Click on Start a new Android Studio Project

Next, follow the instructions provided and keep all other entries as default till the final step. Once your project is created successfully, you will have following project screen

Anatomy of Android Application S.N. Folder, File & Description 1 src This contains the .java source files for your project. By default, it includes a MainActivity.java source file having an activity class that runs when your app is launched using the app icon. 2 gen This contains the .R file, a compiler-generated file that references all the resources found in your project. You should not modify this file. 3 bin This folder contains the Android package files .apk built by the ADT during the build process and everything else needed to run an Android application. 4 res/drawable-hdpi This is a directory for drawable objects that are designed for high-density screens. 5 res/layout This is a directory for files that define your app's user interface. 6 res/values This is a directory for other various XML files that contain a collection of resources, such as strings and colours definitions. 7 AndroidManifest.xml This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.

The Main Activity File The main activity code is a Java file MainActivity.java. This is the actual application file which ultimately gets converted to a Dalvik executable and runs your application. Following is the default code generated by the application wizard for Hello World! application − package com.example.hod_it.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } R.layout.activity_main refers to the activity_main.xml file located in the res/layout folder. The onCreate() method is one of many methods that are figured when an activity is loaded.

The Manifest File <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hod_it.helloworld"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> Whatever component you develop as a part of your application, you must declare all its components in a manifest.xml which resides at the root of the application project directory. This file works as an interface between Android OS and your application, so if you do not declare your component in this file, then it will not be considered by the OS. The Strings File The R File The Layout File

Android Activities Callback Description onCreate() This is the first callback and called when the activity is first created. onStart() This callback is called when the activity becomes visible to the user. onResume() This is called when the user starts interacting with the application. onPause() The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed. onStop() This callback is called when the activity is no longer visible. onDestroy() This callback is called before the activity is destroyed by the system. onRestart() This callback is called when the activity restarts after stopping it.

Example

Android Intents Intents are asynchronous messages which allow application components to request functionality from other Android components. Intents allow you to interact with components from the same applications as well as with components contributed by other applications. For example, an activity can start an external activity for taking a picture. Intent can be used to: Start an Activity Start sub-activity. Start a Service.

Types of Intent Explicit Intent: An application can define the target component directly in the intent Implicit Intent: Ask the Android system to evaluate registered components based on the intent data.

Explicit Intent example

Steps Create "Empty Activity" project named ExplicitIntentExample

By double-clicking on the components on the interface, you can set the ID and text  for them: EditText 1: ID: text_firstName Properties layout_width: fill_parent EditText 2: ID: text_lastName TextView: ID: text_feedback Text: <Feedback> Properties: gravity: center_horizontal

Button: ID: button_greeting Text: Show Greeting Properties: onClick: showGreeting

activity_explicit_intent.xml <?xml version="1.0" encoding="utf-8"?> <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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.hod_it.explicitintentexample.ExplicitIntentActivity"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="<Feedback>" android:id="@+id/text_feedback" android:layout_alignParentBottom="true" android:layout_marginBottom="92dp" android:singleLine="true" android:layout_centerHorizontal="true" android:textAlignment="center" android:gravity="center_horizontal"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show Greeting" android:id="@+id/button_greeting" android:onClick="showGreeting" android:layout_above="@+id/text_feedback" android:layout_centerHorizontal="true" android:layout_marginBottom="68dp" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/text_firstname" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/text_lastname" android:layout_below="@+id/text_firstname" android:layout_centerHorizontal="true" android:layout_marginTop="51dp" /> </RelativeLayout>

When users click the button, the program will call a other Activity displays a greeting. You need to create an Activity with name GreetingActivity.

Change the attributes for components on the interface: TextView ID: text_greeting Text: <Greeting> Properties: layout_width: fill_parent gravity: center_horizontal Button: ID: button_back Properties onClick: backClicked

activity_greeting.xml <?xml version="1.0" encoding="utf-8"?> <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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.hod_it.explicitintentexample.GreetingActivity"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="<Greeting>" android:id="@+id/text_greeting" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="65dp" android:textAlignment="center" android:gravity="center_horizontal"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Back" android:id="@+id/button_back" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="165dp" android:onClick="backClicked" /> </RelativeLayout>

ExplicitIntentActivity.java package com.example.hod_it.explicitintentexample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class ExplicitIntentActivity extends AppCompatActivity { private EditText textFirstName; private EditText textLastName; private TextView textFeedback; public static final int MY_REQUEST_CODE = 100; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_explicit_intent); this.textFirstName = (EditText)this.findViewById(R.id.text_firstname); this.textLastName = (EditText)this.findViewById(R.id.text_lastname); this.textFeedback = (TextView)this.findViewById(R.id.text_feedback); } // When 'Greeting Activity' completed, it sends back a feedback. // (If you have started it by startActivityForResult()) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == MY_REQUEST_CODE ) { String feedback = data.getStringExtra("feedback"); this.textFeedback.setText(feedback); } else { this.textFeedback.setText("!?"); } } // The method is called when the user clicks on "Show Greeting" button. public void showGreeting(View view) { String firstName= this.textFirstName.getText().toString(); String lastName= this.textLastName.getText().toString(); Intent intent = new Intent(this,GreetingActivity.class); intent.putExtra("firstName", firstName); intent.putExtra("lastName", lastName); // Start Activity and no need feedback. // this.startActivity(intent); // Start Activity and get feedback. this.startActivityForResult(intent, MY_REQUEST_CODE); } }

GreetingActivity.java package com.example.hod_it.explicitintentexample; import android.app.Activity; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.TextView; public class GreetingActivity extends AppCompatActivity { private String firstName; private String lastName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_greeting); // Intent is passed into Intent intent = this.getIntent(); this.firstName= intent.getStringExtra("firstName"); this.lastName = intent.getStringExtra("lastName"); String greeting = "Hello "+ firstName+" "+ lastName; TextView textGreeting =(TextView) this.findViewById(R.id.text_greeting); textGreeting.setText(greeting); } // When completed this Activity, send feedback to the caller. @Override public void finish() { // Prepare data intent Intent data = new Intent(); data.putExtra("feedback", "I'm "+ this.firstName+", Hi!"); // Activity finished ok, return the data this.setResult(Activity.RESULT_OK, data); super.finish(); } // The method is called when the user clicks the Back button. public void backClicked(View view) { // Calling onBackPressed(). // Gọi phương thức onBackPressed(). this.onBackPressed(); } }

AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hod_it.explicitintentexample"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".ExplicitIntentActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".GreetingActivity"></activity> </application> </manifest>

Home-Work: Add Middle Name in First Screen Display First Name, Middle Name and Last Name With Message Hello How are you!!!.

Implicit intent Implicit intents: These do not specify a target component, but include enough information for the system to determine which of the available components is best to run for that intent. Consider an app that lists the available restaurants near you. When you click a particular restaurant option, the application has to ask another application to display the route to that restaurant. To achieve this, it could either send an explicit intent directly to the Google Maps application, or send an implicit intent, which would be delivered to any application that provides the Maps’ functionality (e.g., Google Maps, Yahoo Maps).

Example with the implicit intent In this example, you will click a Button which will show you a website by URL, you create an  implicitly Intent, Intent sent to the Android system to decide which  components will be  opened , maybe in your equipment installs many different browsers (Firefox, Chrome, ..), the device will open it in your default browser or your preferred browser In addition examples also include: Send an email