DKU-MUST Mobile ICT Education Center 10. Activity and Intent.

Slides:



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

Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Android 02: Activities David Meredith
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.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Android activities 1 CS300. What makes an app?  Activities: presentation layer  Services: invisible workers  Content Providers: databases  Intents:
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Mobile Programming Pertemuan 6 Presented by Mulyono Poltek NSC Surabaya.
@2011 Mihail L. Sichitiu1 Android Introduction Application Fundamentals.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
CS378 - Mobile Computing Anatomy of an Android App and the App Lifecycle.
Intro to Android Programming George Nychis Srinivasan Seshan.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
Introducing the Sudoku Example
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
© 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.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
Rajab Davudov. Agenda Eclipse, ADT and Android SDK APK file Fundamentals – Activity – Service – Content Provider – Broadcast Receiver – Intent Hello World.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Mobile Application Development using Android Lecture 2.
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
10/10/2015 E.R.Edwards 10/10/2015 Staffordshire University School of Computing Introduction to Android Overview of Android System Android Components Component.
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.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.
Lecture 2: Android Concepts
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
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.
Android Application -Architecture.
Activity and Fragment.
CS371m - Mobile Computing Services and Broadcast Receivers
Lecture 2 Zablon Ochomo Android Programming Lecture 2 Zablon Ochomo
Instructor: Mazhar Hussain
MAD.
Activities and Intents
Android Mobile Application Development
The Android Activity Lifecycle
Android Application Development android.cs.uchicago.edu
Android Programming Lecture 9
Application Fundamentals
Application Development A Tutorial Driven Course
Activities and Intents
HNDIT2417 Mobile Application Development
Activities and Intents
Android Developer Fundamentals V2 Lesson 5
Mobile Programming Dr. Mohsin Ali Memon.
Mobile Programming Dr. Mohsin Ali Memon.
Android Development Tools
CIS 470 Mobile App Development
Presentation transcript:

DKU-MUST Mobile ICT Education Center 10. Activity and Intent

Page  2 Goal Learn the concept of Activity. Learn the concept Intent and how to use the Intent Learn about the life cycle of the Activity.

Page  3 1. Activity, Intent ▶ Android 4 components  Android 4 components (1/2) Activity visual user interface focused on a single thing a user can do. Service no visual interface – they run in the background. (Regardless of the visible screen ) Service creation → Service start → service finish(close, end) Broadcast Receiver If you have broadcast message(Text messages arrive, Battery discharge, Removable SD Card, Changes in the network environment, etc…) response Content providers allow data exchange between applications

Page  4 1. Activity, Intent ▶ Android 4 components  Activity An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an , or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows. An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack"). When a new activity starts, it is pushed onto the back stack and takes user focus. The back stack abides to the basic "last in, first out" stack mechanism, so, when the user is done with the current activity and presses the Back button, it is popped from the stack (and destroyed) and the previous activity resumes. (The back stack is discussed more in the Tasks and Back Stack document.) When an activity is stopped because a new activity starts, it is notified of this change in state through the activity's lifecycle callback methods. There are several callback methods that an activity might receive, due to a change in its state—whether the system is creating it, stopping it, resuming it, or destroying it—and each callback provides you the opportunity to perform specific work that's appropriate to that state change. For instance, when stopped, your activity should release any large objects, such as network or database connections. When the activity resumes, you can reacquire the necessary resources and resume actions that were interrupted. These state transitions are all part of the activity lifecycle.

Page  5 1. Activity, Intent ▶ Android 4 components  Service A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background. A service can essentially take two forms: Started A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. Usually, a started service performs a single operation and does not return a result to the caller. For example, it might download or upload a file over the network. When the operation is done, the service should stop itself. Bound A service is "bound" when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed. Although this documentation generally discusses these two types of services separately, your service can work both ways—it can be started (to run indefinitely) and also allow binding. It's simply a matter of whether you implement a couple callback methods: onStartCommand() to allow components to start it and onBind() to allow binding. Regardless of whether your application is started, bound, or both, any application component can use the service (even from a separate application), in the same way that any component can use an activity—by starting it with an Intent. However, you can declare the service as private, in the manifest file, and block access from other applications. This is discussed more in the section about Declaring the service in the manifest.

Page  6 1. Activity, Intent ▶ Android 4 components  Broadcast Receiver Base class for code that will receive intents sent by sendBroadcast(). If you don't need to send broadcasts across applications, consider using this class with LocalBroadcastManager instead of the more general facilities described below. This will give you a much more efficient implementation (no cross-process communication needed) and allow you to avoid thinking about any security issues related to other applications being able to receive or send your broadcasts. You can either dynamically register an instance of this class with Context.registerReceiver() or statically publish an implementation through the tag in your AndroidManifest.xml. Note: If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won't receive intents when paused, and this will cut down on unnecessary system overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back in the history stack. There are two major classes of broadcasts that can be received: Normal broadcasts (sent with Context.sendBroadcast) are completely asynchronous. All receivers of the broadcast are run in an undefined order, often at the same time. This is more efficient, but means that receivers cannot use the result or abort APIs included here. Ordered broadcasts (sent with Context.sendOrderedBroadcast) are delivered to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers. The order receivers run in can be controlled with the android:priority attribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order. Even in the case of normal broadcasts, the system may in some situations revert to delivering the broadcast one receiver at a time. In particular, for receivers that may require the creation of a process, only one will be run at a time to avoid overloading the system with new processes. In this situation, however, the non-ordered semantics hold: these receivers still cannot return results or abort their broadcast.

Page  7 1. Activity, Intent ▶ Android 4 components  Content Providers Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process. When you want to access data in a content provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client. The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider. The provider object receives data requests from clients, performs the requested action, and returns the results. You don't need to develop your own provider if you don't intend to share your data with other applications. However, you do need your own provider to provide custom search suggestions in your own application. You also need your own provider if you want to copy and paste complex data or files from your application to other applications. Android itself includes content providers that manage data such as audio, video, images, and personal contact information. You can see some of them listed in the reference documentation for the android.provider package. With some restrictions, these providers are accessible to any Android application.

Page  8 1. Activity, Intent ▶ Activity Overview  Add a Activity Generates one activity per screen In general, for each activity, create an XML file using one TestActivity.java Code TestActivity.java is activity. Because TestActivity inherits Activity class.

Page  9  Activity Test When you click button in the main activity(main screen), show the second activity(second screen)  Project Info. Project Name : Project10_1 Package Name : com.cookandroid.project10_1 build SDK : Goolge API 15 or 16 Minimum Required SDK : API 15 or 16 Activity Name : Project10_1Activity Layout Name : main Title : Project10_1 [Practice 10-1] Add a new activity(1/6) 1. Activity, Intent ▶ Activity

Page  10  Design the Screen Make the 2 file ( main.xml, second.xml ) 1. Activity, Intent ▶ Activity [Practice 10-1] Add a new activity(2/6)

Page  11  Java Coding 1 Add a new activity(SecondActivity.java) file Autocomplete the onCreate( ) method. - override 1. Activity, Intent ▶ Activity [Practice 10-1] Add a new activity(3/6)

Page  12  Java coding 2 1. Activity, Intent ▶ Activity [Practice 10-1] Add a new activity(4/6)

Page  13  Java coding 3 1. Activity, Intent ▶ Activity [Practice 10-1] Add a new activity(5/6)

Page  14  Project execution and error messages Activity can be used as additional means must be registered in AndroidManifest.xml. 1. Activity, Intent ▶ Activity [Practice 10-1] Add a new activity(6/6)

Page  15  Explicit Intent and Data Transfer Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application. In many cases, the data type can be inferred from the URI — particularly content: URIs, which indicate that the data is located on the device and controlled by a content provider (see the separate discussion on content providers). But the type can also be explicitly set in the Intent object. The setData() method specifies data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it as both a URI and a MIME type. The URI is read by getData() and the type by getType(). 1. Activity, Intent ▶ Explicit Intent

Page  16  RatingBar (1/2) 1. Activity, Intent ▶ Explicit Intent

Page  17  RatingBar(2/2) 1. Activity, Intent ▶ Explicit Intent

Page  18  Implicit Intent (1/2) Implicit intents do not name a target (the field for the component name is blank). Implicit intents are often used to activate components in other applications. 2. Activity, Intent Application ▶ Implicit Intent

Page  19  Implicit Intent (2/2) ACTION_DIAL tel:123 - Display the phone dialer with the given number filled in. Add a permission in the AndroidMahnifest.xml 2. Activity, Intent Application ▶ Implicit Intent

Page  20  Example of Implicit Intent : XML code 2. Activity, Intent Application ▶ Implicit Intent

Page  21  Example of Implicit Intent : Java code (1/3) 2. Activity, Intent Application ▶ Implicit Intent

Page  22  Example of Implicit Intent : Java code (2/3) 2. Activity, Intent Application ▶ Implicit Intent

Page  23  Example of Implicit Intent : Java code(3/3) 2. Activity, Intent Application ▶ Implicit Intent

Page  24  Activity Lifecycle 2. Activity, Intent Application ▶ Activity Life Cycle

Page  25  Activity Lifecycle Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits. An activity has essentially four states: If an activity in the foreground of the screen (at the top of the stack), it is active or running. If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations. If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere. If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state. The following diagram shows the important state paths of an Activity. The square rectangles represent callback methods you can implement to perform operations when the Activity moves between states. 2. Activity, Intent Application ▶ Activity Life Cycle

DKU-MUST Mobile ICT Education Center