Lecture 2: Android Concepts

Slides:



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

Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Informatica – Scienza e Ingegneria Università di Bologna.
Android 02: Activities David Meredith
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Mobile Application Development
Mobile Programming Pertemuan 6 Presented by Mulyono Poltek NSC Surabaya.
@2011 Mihail L. Sichitiu1 Android Introduction Application Fundamentals.
INTERNATIONAL SUMMER ACADEMIC COURSE UNIVESITY OF NIS ISAC – Android programming.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
Mobile Application Development with ANDROID Tejas Lagvankar UMBC 29 April 2009.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
박 종 혁 컴퓨터 보안 및 운영체제 연구실 MobiSys '11 Proceedings of the 9th international conference on Mobile systems, applications,
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
Copyright© Jeffrey Jongko, Ateneo de Manila University Android.
Rajab Davudov. Agenda Eclipse, ADT and Android SDK APK file Fundamentals – Activity – Service – Content Provider – Broadcast Receiver – Intent Hello World.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Overview of Android Application Development
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Linking Activities using Intents How to navigate between Android Activities 1Linking Activities using Intents.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
Activity Android Club Agenda Hello Android application Application components Activity StartActivity.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Introducing Intents Intents Bind application components and navigate between them Transform device into collection of interconnected systems Creating a.
Lecture 2: Android Concepts
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
6/12/2016 TOPS Technologies- Android training -
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Introduction to Android Programming
The Basics of Android App Development Sankarshan Mridha Satadal Sengupta.
Android Application -Architecture.
Intents and Broadcast Receivers
Lecture 2: Android Concepts
Android 01: Fundamentals
Android Application Development 1 6 May 2018
Android 5: Interacting with Other Apps
CS371m - Mobile Computing Services and Broadcast Receivers
Linking Activities using Intents
Lecture 2 Zablon Ochomo Android Programming Lecture 2 Zablon Ochomo
Android Runtime – Dalvik VM
MAD.
CMPE419 Mobile Application Development
Android Introduction Camera.
Android Programming Lecture 9
Android Programming Lecture 5
Application Fundamentals
Application Development A Tutorial Driven Course
Activities and Intents
Activities and Intents
Android Developer Fundamentals V2 Lesson 5
Android Platform, Android App Basic Components
Emerging Platform#3 Android & Programming an App
Activities and Intents
Application Fundamentals
Objects First with Java
CMPE419 Mobile Application Development
Chapter 5 Your Second Activity.
Presentation transcript:

Lecture 2: Android Concepts Topics: Framework, Components, Intent

Android Interfaces and Architecture

A multi-user Linux system Android Fundamentals What kind of an OS is Android? User ID1 User ID2 Android OS is a multi-user Linux system. Each app is like a different user (unique user ID). Each app lives in its own security sandbox. Every app runs in its own Linux process. Android starts/terminates the process based on the need for an app's components to be executed. Android OS A multi-user Linux system (classroom.cs.unc.edu)

Android Fundamentals What is an APK file? Android SDK tools compile your java source files into .dex files, and then zip .dex file, project resources (images, layouts etc.) and the manifest file into an APK. Unzip any android .apk and you will see these files inside it. You can find an .apk file inside: YourProject/app/build/outputs/apk Note: You need to Build .apk from Android Studio at least once to see the apk folder in your laptop.

Android Fundamentals What is ART? ART = Android Runtime (it’s like Java Runtime) Pros: Faster application execution. Cons: Longer installation time, more storage requirement. ART DEX dex2oat native code ART runtime AOT (ahead of time) compilation i.e. when an app is installed

Four Types of App Components Activity Service Content Provider Broadcast Receiver Activity Activity Activity Service Content Provider Activity Broadcast Receiver Broadcast Receiver Broadcast Receiver An Example APP

App Components Activity Service Content Provider Broadcast Receiver APP from the last class

The Manifest File AndroidManifest.xml – we must declare all the app components (i.e., activity, service etc.) in this file. This file also contains: Permissions (e.g., location, storage etc.) API Level (min and target) HW/SW features used Other API libraries

The Manifest File <activity> elements for activities <service> elements for services <provider> elements for content providers <receiver> elements for broadcast receivers Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. Broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by calling registerReceiver().

1. Activity An activity represents a single screen with a user interface.

2. Service Runs in the background to perform long running operations, or does some work for remote processes. A service does not provide a user interface. Yes, you can create your own services too. Settings>Developer Options>Running Services

3. Content Provider A content provider manages a shared set of app data. Other apps can query or even modify the data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your app can access.

4. Broadcast Receiver A broadcast receiver is a component that responds to system-wide broadcast announcements. Originate from the system—the battery is low, or a picture was captured. Initiated by an App – download completed. Broadcast receivers don't display a user interface, they may create a status bar notification.

Multiple Entry Points One component can start another component App Activity Activity Activity User Service Content Provider Activity Another App Broadcast Receiver Broadcast Receiver Broadcast Receiver Another App An Example APP

Example One component can start another component

“Intent”: Activating components Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. Intents bind individual components to each other at runtime. Intent

“Intent”: Activating Component You can start an activity (or give it something new to do) by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result). You can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). Or you can bind to the service by passing an Intent to bindService(). You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast(). You can perform a query to a content provider by calling query() on a ContentResolver.

Explicit Intents Explicit – using the component’s class name. Activity1 Intent x = new Intent(this, Activity2.class); startActivity(x); Activity2

Explicit Intent Example – with data We want to switch to an Activity and pass some data to it. Activity1 Intent X = new Intent(this, Activity2.class); X.setData(“some Uri”); startActivity(X); Activity2 To access the data in the other Activity: “getIntent().getData()”

Try this at home We want to pass strings between Activities: Create Activity1 (add a button) Create Activity2 (add a textview) Send Intent from Activity1 to Activity2 Send Intent with Data

Explicit Intent vs. Implicit Intent Mr. Thor, can I have your hammer? Who can share a hammer, please? me I need HAMMER Android OS

Implicit Intents Implicit – using some reserved keywords. You provide type of action to be performed You can provide data to be used Multiple matching Activities may exist.

Implicit Intent Example We want to VIEW a webpage in a browser: Intent w = new Intent( Intent.ACTION_VIEW, Uri.parse(“http://www.unc.edu”) );

Another Implicit Intent Example We want to VIEW a location on a map: Intent w = new Intent( Intent.ACTION_VIEW, Uri.parse(“geo:35.909715, -79.052779?Z=14”) );

What if no one to receive my Intent? Your App will crash! To get a list of matching Apps: To verify that the Intent will resolve to an Activity: getPackageManager().queryIntentActivities( your_intent, PackageManager.MATCH_DEFAULT_ONLY ); X.resolveActivity(getPackageManager()) != null

Getting Results Back We want an Activity to do something and return the result back to us. Step1: startActivityForResult(intent_object, SOME_REQ_CODE); Step2: @Override protected void onActivityResult (int requestCode, int resultCode, Intent data) { }

Example: Implicit Intent with Camera Intent w = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivity(w); Just uses the camera. Returns no photos.

Getting the Image Back Intent w = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(w, 1); @Override protected void onActivityResult(int requestCode, int resultCode, Intent x) { //if (requestCode == 1 && resultCode == RESULT_OK) Bundle extras = x.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); img = (ImageView) findViewById(R.id.imageView); img.setImageBitmap(imageBitmap); }

How to receive an Intent? Suppose, your App can send or share a text. Other Activity Your Activity ACTION_SEND Plain text <intent-filter>         <action android:name="android.intent.action.SEND"/>         <category android:name="android.intent.category.DEFAULT"/>         <data android:mimeType="text/plain"/> </intent-filter> You must include the CATEGORY_DEFAULT to receive implicit intents.

How to receive an Intent? You specify <intent-filter> in your manifest. Other Activity Your Activity ACTION_MAIN LAUNCHER <activity android:name="MainActivity">     <!-- This activity is the main entry, should appear in app launcher -->     <intent-filter>         <action android:name="android.intent.action.MAIN" />         <category android:name="android.intent.category.LAUNCHER" />     </intent-filter> </activity>

Practice Let us try the camera example (implicit intent)

References (study these) http://source.android.com/source/index.html https://source.android.com/devices/architecture http://developer.android.com/guide/components/fundamentals.html http://developer.android.com/training/basics/intents/sending.html http://developer.android.com/guide/components/intents-filters.html http://developer.android.com/training/camera/photobasics.html https://android.jlelse.eu/closer-look-at-android-runtime-dvm-vs-art- 1dc5240c3924 https://events.linuxfoundation.org/images/stories/slides/abs2013_garg entas.pdf