Activities, Fragments, and Intents

Slides:



Advertisements
Similar presentations
CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
Advertisements

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.
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.
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.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
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.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
Activity Android Club Agenda Hello Android application Application components Activity StartActivity.
New Activity On Button Click via Intent. App->res->Layout->Blank Activity A new xml file is created and a new class is added to java folder. In manifest.xml.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Chapter 2: Simplify! The Android User Interface
Introduction to android
Android Application -Architecture.
Lab7 – Advanced.
Concurrency in Android
Mobile Application Development BSCS-7 Lecture # 2
Activity and Fragment.
Java Examples Embedded System Software
Programming with Android:
Adapting to Display Orientation
Basic Activities and Intents
Android Boot Camp for Developers Using Java, 3E
Activities, Fragments, and Events
CS499 – Mobile Application Development
Mobile Application Development BSCS-7 Lecture # 6
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
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
Picasso Revisted.
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.
CIS 493/EEC 492 Android Sensor Programming
Activities and Intents
Objects First with Java
Activities and Intents
SE4S701 Mobile Application Development
Activities and Fragments
Android Development Tools
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Activities, Fragments, and Intents

Activities Activity – window that contains the user interface of your application May have zero or more activities Many purpose of activity is to interact with user Activity Life Cycle

Fragments Android 4.0 introduced Fragments Fragment is miniature activity that can be grouped to form an activity

Intent Intent – glue that enables different activities from different applications to work together seamlessly Used to call built-in applications such as: the Browser Phone Maps Etc.

Activity Activity base class defines a series of events that govern the life cycle of an activity onCreate() – called when the activity is first created onStart() – called when activity becomes visible to user onResume() – called when activity starts interacting with user onPause() – called when current activity is being paused and previous activity is being resumed onStop() – called when activity is no longer visible to user onDestroy() – called before activity is destroyed by system onRestart() – called when activity has been stopped and is restarting again

Activity import android.os.Bundle; Import android.app.Activity public class MainActivity extends Activity { /** Called when activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }

Activity By default, the activity created for you contains the onCreate() event. User Interface component is loaded using XML file defined in your res/layout folder – main.xml Every activity you have in your application must be declared in your AndroidManifest.xml file

Activity Life Cycle

Activity An Activity is destroyed when you click the Back button The state the Activity is in will be lost Additional code is required to preserve its state when it is destroyed Guidelines to follow: Use onCreate() to create and instantiate objects you will be using in your application Use onResume() to start any services or code that needs to run while your Activity is in the foreground Use the onPause() to stop any services or code that does not need to run when your Activity is not in the foreground Use the onDestroy() to free up resources before your Activity is destroyed

Link Activities using Intents In Android, you navigate between activities through an Intent An Activity is made up of: a UI component (main.xml) and a class component (.java file) AndroidManifest.xml file, add the Activity with an Intent <activity android:name=".SecondActivity" android:label="Second Activity" > <intent-filter> <action android:name="com.example.SecondActivity" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>

Link Activities using Intents public void onClick(View view) { startActivity(new Intent("com.example.SecondActivity")); } Activities can be invoked by any application running on the device. Fundamental concept in Android startActivity() method invokes another Activity Does not return a result to the current Activity To pass data back from an Activity, use the startActivityForResult() method

Fragments