Activities and Intents

Slides:



Advertisements
Similar presentations
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Advertisements

CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
Programming with Android: Activities
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.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
CS378 - Mobile Computing Anatomy of an Android App and the App Lifecycle.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Android Info mostly based on Pro Android 3.  User Applications  Java Libraries – most of Java standard edition ◦ Activities/Services ◦ UI/Graphics/View.
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Overview of Android Application Development
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
DKU-MUST Mobile ICT Education Center 10. Activity and Intent.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
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.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Android Fragments. Slide 2 Lecture Overview Getting resources and configuration information Conceptualizing the Back Stack Introduction to fragments.
Editing a Twitter search. Viewing search results in a browser.
Android Application -Architecture.
Mobile Applications (Android Programming)
Mobile Application Development BSCS-7 Lecture # 2
Activity and Fragment.
CS371m - Mobile Computing Services and Broadcast Receivers
Basic Activities and Intents
Instructor: Mazhar Hussain
Activities, Fragments, and Events
Mobile Application Development BSCS-7 Lecture # 6
Mobile Applications (Android Programming)
MAD.
Android Activities An application can have one or more activities, where Each activity Represents a screen that an app present to its user Extends the.
Anatomy of an Android App and the App Lifecycle
Widgets & Fragments Kalin Kadiev Astea Solutions AD.
Android Mobile Application Development
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
The Android Activity Lifecycle
ANDROID UI – FRAGMENTS UNIT II.
Anatomy of an Android App and the App Lifecycle
Activity Lifecycle Fall 2012 CS2302: Programming Principles.
Android Topics Android Activity Lifecycle and Experiment Toast
Activities and Intents
Activities and Intents
HNDIT2417 Mobile Application Development
Programming Mobile Applications with Android
CIS 470 Mobile App Development
Activity Lifecycle.
Activities and Intents
Android Developer Fundamentals V2 Lesson 5
Activities and Intents
Mobile Programming Dr. Mohsin Ali Memon.
SE4S701 Mobile Application Development
Activities and Fragments
Android Development Tools
Preference Activity class
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Activities and Intents CHAPTER 3 Activities and Intents

Chapter objectives: Explore an Activity’s Lifecycle Learn about saving and restoring an Activity Understand Intents and how they are used with multiple Activities Become familiar with passing data between Activities Implement applications that require basic animation Activity transitions Study Scene transitions

3.1 Activity Lifecycle All applications are composed of at least one Activity class In most cases, applications will require the use of several activities Activities in an application are often loosely connected to each other. Information can be passed from one activity to another, but they remain distinct and separate in every other way. Every application has one activity class that serves as the main activity Each time a new activity starts, the previous activity is paused and its status is preserved by the Android system.

Activities must be declared in the AndroidManifest Activities must be declared in the AndroidManifest.xml file in order to be accessible to the system Activities are defined using the <activity> tag. An <activity> must be added as a child to the <application> element

The activities in an application are implemented as a subclass of Activity The Activity class is an important part of every application’s overall lifecycle When an application is first loaded, its main activity, specified within the AndroidManifest, is immediately created Once the main activity is started, it is given a window in which to draw its layout Its layout is its associated user interface screen.

 The Activities in an application are managed by an Activity stack New activities are pushed onto the top of the stack and become the running activity

The Activity class defines the following seven callback methods, beginning with the creation of the Activity and ending with its destruction  onCreate()  onStart()  onResume()  onPause()  onStop()  onRestart()  onDestroy() 

If a paused or stopped activity requires destruction due to a system need for more memory, the activity will need to be recreated again. This will be done by calling onCreate().  onStart() is always to be called after onRestart()  onStop() is called when the activity is no longer visible to the user onDestroy() performs final cleanup prior to an activity’s destruction

3.2 Starting, Saving, and Restoring an Activity When an activity is paused or stopped, the state of the activity is retained  When the system destroys an activity in order to recover memory, the memory for that activity object is also destroyed

A Bundle is a container for the activity state information that can be saved The following is an incomplete list of these methods:   putChar() putString() putBoolean() putByte() putFloat() putLong() putShort() putParcelable()  

Recover the saved state from the Bundle that the system passes to the activity onCreate() and onRestoreInstanceState() callback methods receive the same Bundle object that contains the instance state information  Check whether the activity’s state (stored in the Bundle object) is null before you attempt to read it If it is null, then the system is creating a new instance of the Activity class, instead of restoring a previous one that was destroyed 

During runtime, the user may alter the screen orientation.   The system will automatically recreate the currently running activity by calling onDestroy(), and then immediately calling onCreate(). Application adapts to new configurations by automatically reloading the application with alternative resources, such as adaptive layouts for different screen size and orientation

3.3 Multiple Activities and the Intent Class Applications that are built with multiple activities need to utilize the Intent class This class provides the framework for the navigation from one screen to another. An Intent object is a message from one component to another component, either within the application or outside the application  

Intents are designed to communicate messages between three application core components Activities Broadcast receivers Service:

3.3.1 Explicit Intents Explicit Intents use a specific name when starting a component This name will be the full Java class name of the activity or service The most common use of an explicit Intent is the launching of a target component with a known name within the currently running application.

3.3.2 Implicit Intents Unlike an explicit Intent, an implicit Intent does not name a specific component it declares a general action to perform, which allows a component from another app to handle it When an implicit Intent is created, the system locates the appropriate target component by comparing the contents of the Intent to an Intent filter Intent filters are declared in the manifest file of other apps located on a given device When the Intent has found a match with the Intent filter, the system starts that component and delivers it to the Intent object.  

3.4 Handling Keyboard Visibility Android shows or hides the soft keyboard when input focus moves into or out of an editable text field The system also makes decisions about how your UI and the text field appear above the keyboard It is possible to specify how you want your layout to appear when the keyboard is visible Android gives focus to the first EditText element in the layout launched by a running activity  

It is also possible to request the focus of a View programmatically requestFocus can be called to give focus to a specific View or to one of its descendants This can be useful in cases when you want to ensure that the keyboard is visible.

3.5 Passing Data   The Android framework provides a simple and flexible approach to working with multiple activities Android also offers an efficient model for passing information between various activities.   Data can be passed as a message object to an activity implemented within the application or an activity outside of the applications  When an Intent object is constructed, its action is specified This represents the action we want the Intent to trigger This action will also send data across process boundaries

It is possible to add extended data to a given Intent This is done using the putExtra() method putExtra() requires two parameters: a name for the data and a String data value The data name must include a package prefix

3.6 Basic Transitions Between Activities The quality of an application can depend on several characteristics, such as content, usability, and design features Enhancements made to interaction design, through the use of animation, can make a fundamental difference in the usability of an application Interaction plays a large role User interfaces are not static designs, but rather engaging and dynamic design patterns

Custom transition animations are resources that can be built by methods in XML code The method overridePendingTransition() allows custom-built transitions to be entering and exiting activities overridePendingTransition() requires two arguments: an enter animation implementation and an exit animation implementation

3.7 Scene Transitions KitKat, Android 4.4, has a transitions framework that supports the definition of scene transitions Scenes are used specifically for transition animations. Scenes can be created as a View hierarchy, much like a layout A scene contains values of various properties in the View hierarchy As scenes enter or exit a View hierarchy, they will be animated based on these properties http://developer.android.com/guide/topics/resources/animation-resource.html