Activities, Fragments, and Events

Slides:



Advertisements
Similar presentations
Android architecture overview
Advertisements

Fragments: Introduction Fragments were introduced in Android 3.0 to support flexible and dynamic UI designs represent portions of an application’s user.
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.
Android Fragments.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Programming with Android: Android Fragments Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
 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.
Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.
Chapter 2: Simplify! The Android User Interface
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
Activities Димитър Н. Димитров Astea Solutions AD.
Class on Fragments & threads. Fragments fragment is a modular section of an activity, which has its own lifecycle, receives its own input events, and.
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.
Android Fragments. Slide 2 Lecture Overview Getting resources and configuration information Conceptualizing the Back Stack Introduction to fragments.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
Chapter 2: Simplify! The Android User Interface
Android Application -Architecture.
Mobile Application Development BSCS-7 Lecture # 2
Activity and Fragment.
Java Examples Embedded System Software
Adapting to Display Orientation
Basic Activities and Intents
Fragment ?.
Fragments: Introduction
CS499 – Mobile Application Development
Mobile Application Development BSCS-7 Lecture # 6
Mobile Applications (Android Programming)
Activities and Intents
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.
Software Engineering in Mobile Computing
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
CIS 470 Mobile App Development
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
Android Programming Tutorial
Programming Mobile Applications with Android
CIS 470 Mobile App Development
Activity Lifecycle.
Activities and Intents
SE4S701 Mobile Application Development
Mobile Programming Dr. Mohsin Ali Memon.
Activities and Fragments
Android Development Tools
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Activities, Fragments, and Events

Topics Covered The life cycle of an activity Customizing the UI using fragments Applying styles and themes to activities Displaying activities as dialog windows Understanding the concept of intents Linking activities using intent objects Displaying alerts using notifications

Understanding Activities

What are activities? A window that contains the UI of an application An application can have zero or more activities Main purpose is to interact with the user Life Cycle: the stages an activitiy goes through from the moment it appears on the screen to the moment it’s hidden.

Creating Activities To create an activity, a Java class that extends the Activity base class is created. import android.app.Activity; … public class Activity101Activity extends Activity { } The activity class loads it UI component using the XML file defined in the res/layout folder.

Declaring Activities Each activity in the application, must be declared in the AndroidManifest.xml file. <activity android:label=“@string/app_name” android:name=“.Activity101Activity”> <intent-filter></intent-filter> </activity>

Activity Base Class onCreate() – Called when the activity is first created onStart() – Called when the activity becomes visible to the user onResume() – Called when the activity starts interacting with the user onPause() – Called when the current activity is being paused and the previous activity is being resumed onStop() – Called when the activity is no longer visible onDestroy() – Called before the activity is destroyed by the system onRestart() – Called when the activity has been stopped and is restarting By default

Figure 1: Activity Life cycle

Applying Styles and Themes By default, an activity occupies the entire screen A dialog theme can be applied to an activity so it appears as a floating dialog

Applying Dialog Theme <application </application> android:icon=“@drawable/ic_launcher” android:theme=“@android:style/Theme.Dialog”> <activity android:label=“@string/app_name” android:name=“.Activity101Activity”> <intent-filter></intent-filter> </activity> </application> Modify the <Activity> element in the AndroidManifest.xml file by adding the android:theme attribute

Hiding Activity Title import android.view.Window; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); } To hide the title of an activity use the requestWindowFeature() method and pass it the Window.FEATURE_NO_TITLE constant

Linking Activities Using Intents When an application has multiple activities they can be navigated through intents. An intent is an abstract description of an operation to be performed. An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.

Fragments

What is a Fragment? A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity. Interaction with fragments is done through FragmentManager, which can be obtained via Activity.getFragmentManager() and Fragment.getFragmentManager(). Some things that you can do with FragmentManager include: Get fragments that exist in the activity, with findFragmentById() (for fragments that provide a UI in the activity layout) or findFragmentByTag() (for fragments that do or don't provide a UI). Pop fragments off the back stack, with popBackStack() (simulating a Back command by the user). Register a listener for changes to the back stack, with addOnBackStackChangedListener().

Figure 2: An example of how two UI modules defined by fragments can be combined into one activity for a tablet design, but separated for a handset design.

Adding Fragments Dynamically It is more useful if fragments are created and added to activites during runtime. Allows for a customizable UI E.g. If the application is running on a smartphone, you might fill the activity with a single fragment; if the activity is running on a tablet, you might then fill the activity with two or more fragments. While fragments allow UI compartmentalization into configurable parts, the real power is realized when fragments are added dynamically to activities during runtime.

Fragment Life Cycle A fragment must always be embedded in an activity and the fragment's lifecycle is directly affected by the host activity's lifecycle. For example, when the activity is paused, so are all fragments in it, and when the activity is destroyed, so are all fragments. However, while an activity is running (it is in the resumed lifecycle state), you can manipulate each fragment independently, such as add or remove them. When you perform such a fragment transaction, you can also add it to a back stack that's managed by the activity—each back stack entry in the activity is a record of the fragment transaction that occurred. The back stack allows the user to reverse a fragment transaction (navigate backwards), by pressing the Back button.

Figure 3. The lifecycle of a fragment (while its activity is running).

Displaying Notifications

For important messages the NotificationManager is used to display a persistent message at the top of the device (commonly known as the status bar, sometimes referred to as the notification bar)

Activities, Fragments, and Events