Basic Activities and Intents

Slides:



Advertisements
Similar presentations
Programming with Android: Activities
Advertisements

Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
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,
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.
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.
Android Info mostly based on Pro Android 3.  User Applications  Java Libraries – most of Java standard edition ◦ Activities/Services ◦ UI/Graphics/View.
CS378 - Mobile Computing Intents.
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
10/10/2015 E.R.Edwards 10/10/2015 Staffordshire University School of Computing Introduction to Android Overview of Android System Android Components Component.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Activities Димитър Н. Димитров Astea Solutions AD.
Lecture 6: Process and Threads Topics: Process, Threads, Worker Thread, Async Task Date: Mar 1, 2016.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Speech Service & client(Activity) 오지영.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Cosc 4735 Nougat API 24+ additions.
Android Application -Architecture.
Concurrency in Android
Lecture 2: Android Concepts
SQLite in Android Landon Cox March 2, 2017.
Activity and Fragment.
Programming with Android:
Mobile Programming Lecture 2
Activities, Fragments, and Events
Fragment ?.
Fragments: Introduction
Mobile Application Development BSCS-7 Lecture # 6
Notifications and Services
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.
Android 9: The Activity Lifecycle
Anatomy of an Android App and the App Lifecycle
Widgets & Fragments Kalin Kadiev Astea Solutions AD.
Android Mobile Application Development
Software Engineering in Mobile Computing
The Android Activity Lifecycle
ANDROID UI – FRAGMENTS UNIT II.
Android Application Development android.cs.uchicago.edu
Android training in Chandigarh. What is ADB ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator.
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
HNDIT2417 Mobile Application Development
Programming Mobile Applications with Android
CIS 470 Mobile App Development
Activity Lifecycle.
Activities and Intents
Objects First with Java
Activities and Intents
SE4S701 Mobile Application Development
Lecture 2: Android Concepts
Activities and Fragments
Android Development Tools
Korea Software HRD Center
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Basic Activities and Intents Landon Cox January 23, 2017

What is an Activity? The basics Activities have a three-part lifecycle Java object “a single, focused thing that the user can do” Represents a screen for the user to interact with Entry point for the system and other code Activities have a three-part lifecycle Can be instantiated Can be visible Can be foregrounded

Launch Process killed Running Shut down onCreate() onStart() onRestart() onResume() Process killed Running onPause() onStop() onDestroy() Shut down

Activity instantiated. Like a constructor. Init UI: setContenView. Launch onCreate() onStart() Activity instantiated. Like a constructor. Init UI: setContenView. onResume() Activity made visible. Register non-user inputs, e.g., new messages Running Activity foregrounded. Start intensive UI widgets, e.g., camera live stream Starting points for three Entire, Visible, and Foreground lifetimes

Entire lifetime Launch Activity instantiated. Like a constructor. onCreate() Activity instantiated. Like a constructor. Init UI: setContenView. Running Activity destroyed. Clean up before shutdown, e.g., save state to DB onDestroy() Shut down

Visible lifetime Launch Activity made visible. onCreate() onStart() onRestart() Activity made visible. Register non-user inputs, e.g., new messages Running Activity no longer visible. Unregister non-user inputs, e.g., new messages onStop() Activity made visible. User returned to Activity. onDestroy() Shut down

Foreground lifetime Launch Activity foregrounded. Start intensive UI widgets, e.g., camera live stream onCreate() onStart() onRestart() onResume() Running onPause() Activity backgrounded. Stop intensive UI widgets, e.g., camera live stream onStop() onDestroy() Shut down

Launch Process killed Running What’s this all about? Shut down onCreate() onStart() onRestart() onResume() Process killed Running onPause() onStop() What’s this all about? onDestroy() Shut down

Activity lifecycle demo

How do we launch an Activity? Android Intents An Intent is a message Each Intent has a destination (action) and payload (data) Intent action Describes the destination Activity (or other component) that should receive message Intent data Provides the receiver with extra information E.g., which URL to display or an email address to message

What Activity should receive this message? Launching ImageGrid What Activity should receive this message? Intent i = new Intent(MainActivity.this, ImageGridActivity.class); startActivity(i);

Is there any data associated with this Intent? Launching ImageGrid Is there any data associated with this Intent? Intent i = new Intent(MainActivity.this, ImageGridActivity.class); startActivity(i);

This is an explicit Intent. We know exactly what Activity should run. Launching ImageGrid This is an explicit Intent. We know exactly what Activity should run. Intent i = new Intent(MainActivity.this, ImageGridActivity.class); startActivity(i);

Launching ImageGrid Intent i = new Intent(MainActivity.this, Can you think of an example when you want something done, but aren’t sure which code to run? Intent i = new Intent(MainActivity.this, ImageGridActivity.class); startActivity(i);

This is an implicit Intent. Displaying a web URL This is an implicit Intent. We want a type of code to run, but don’t really care or know what code. Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(" http://www.google.com/images?q=duke")); startActivity(browserIntent);

Let’s change our ImageViewer! Displaying a web URL Let’s change our ImageViewer! Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(" http://www.google.com/images?q=duke")); startActivity(browserIntent);

Displaying a web URL Intent browserIntent = This is still an implicit Intent. But we can set a preference for which code runs. Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(" http://www.google.com/images?q=duke ")); browserIntent.setPackage("com.android.chrome"); startActivity(browserIntent);

Let’s update our ImageViewer! Displaying a web URL Let’s update our ImageViewer! Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(" http://www.google.com/images?q=duke ")); browserIntent.setPackage("com.android.chrome"); startActivity(browserIntent);

How does Android know which Activities could receive this Intent? Displaying a web URL How does Android know which Activities could receive this Intent? Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(" http://www.google.com/images?q=duke ")); startActivity(browserIntent);

Intent filters Restricts which actions the Activity will accept (Intent Action must match) <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

Intent filters Describes categories of Intent Activity accepts <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> Describes categories of Intent Activity accepts (Intent categories must match all)