Manifest File, Intents, and Multiple Activities. Manifest File.

Slides:



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

Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Informatica – Scienza e Ingegneria Università di Bologna.
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 101 Application Fundamentals January 29, 2010.
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
SMS. Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Development (Basics)
Getting Started with Android Development Rohit Ghatol.
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.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
Mobile Programming Lecture 9 Bound Service, Location, Sensors, IntentFilter.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters.
Intent Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Linking Activities using Intents How to navigate between Android Activities 1Linking Activities using Intents.
Activity Android Club Agenda Hello Android application Application components Activity StartActivity.
Mobile Programming Midterm Review
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.
Introducing Intents Intents Bind application components and navigate between them Transform device into collection of interconnected systems Creating a.
Activities and Intents Richard S. Stansbury 2015.
Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity.
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
Lecture 2: Android Concepts
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Mobile Applications (Android Programming)
Intents and Broadcast Receivers
Lecture 2: Android Concepts
Mobile Application Development BSCS-7 Lecture # 2
several communicating screens
Programming with Android:
Android 5: Interacting with Other Apps
Linking Activities using Intents
CS499 – Mobile Application Development
Activities and Intents
Android Introduction Camera.
Android Programming Lecture 5
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Activities and Intents
Activities and Intents
Activities and Intents
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Objects First with Java
Activities and Intents
Lecture 2: Android Concepts
Objects First with Java
Activities and Fragments
Chapter 5 Your Second Activity.
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CA16R405 - Mobile Application Development (Theory)
Presentation transcript:

Manifest File, Intents, and Multiple Activities

Manifest File

Manifest file AndroidManifest.xml – required – indicates application information activities (within application tag) Android SDK version activities used within the app services that will be used (Web, phone, etc.) other aspects

Manifest file – Application tag <application android:allowBackup="true" > <activity android:name="edu.csci153.MultActivities" > <activity android:name="Screen2" android:label="Second Screen" >

Manifest File Exploring the tag – android:allowBackup=“true” allows app and data to be backed up with a system restore – Icon to display in the drawer – Name of the icon in the drawer – child of

Manifest File Exploring the tag – android:name=“edu.csci153.MultActivities” Associated.java file – Text that appears in title bar when this activity is displayed – child of

Manifest File Exploring the tag – Indicates this is the main entry point of the application – Indicates that the activity should be launched – Without these lines, the application is started but no activity is presented intent-filters ‘filter’ what an object can do – if there is no action defined within the filter, they implicitly deny that the action can be performed

Intents

Intent Class within Android – android.content.Intent – contains information regarding some action to be performed starting the phone dialer starting an activity opening a web page other

Intent Example Starting the phone dialer (no special permission needed) Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel: ")); startActivity(intent);

Intent Example Opening a web page – Permission in manifest file well over 100 different permissions – access internet, bluetooth, vibrate phone, change wall paper, etc. – uses-permission tag (child of manifest tag) – Intent in corresponding java file Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(” startActivity(intent);

Intent Example Opening an Activity Intent intent = new Intent(this, Screen2.class); startActivity(intent); ‘this’ refers to the current activity Screen2.class refers to the class file associated with the new activity to be opened – implies a corresponding Sreen2.java file exists – activity MUST be referenced in the manifest file

Intents Methods in the Intent class – The intent class has many methods to put or retrieve data useful when one Activity launches another – put methods used by current Activity that will instantiate another Activity – get methods used by new instantiated Activity

Intents put… methods – put… allows information to be passed from current Activity to newly instantiated Activity putExtra – simple data types and arrays » passing an integer i.putExtra(“Key1”, 17); Key1 – name of the integer to be passed 17 – contents of the integer to be passed » passing a String i.putExtra(“Key2”, “Value”); » passing an array i.putExtra(“Key3”, new int [] {1, 2, 3});

Intents get… methods – get… allows information to be retrieved by the newly instantiated Activity get…Extra – datatype must be known – getting an integer » getIntent().getIntExtra(“Key1”, 0); » 2 nd argument is default value in case Key1 does not exist, or is not an integer – getIntent().getStringExtra(“Key2”); » retrieves value associated with Key2 » if no value, null is returned – no default option – getting an array » int [] z = getIntent().getIntArrayExtra(”Key3"); » if no value, null is returned – no default option

Activities Helpful hints about Activities – Each Activity has: a corresponding.java file at least one corresponding.xml file (may have additional menu file) – Each Activity must be referenced in the manifest file – The Activity class has a getIntent() method to retrieve the intent that initiated it – Each activity has a lifecycle

Activity lifecycle methods Most important (signatures) – protected void onCreate(Bundle savedInstanceState); called when created or phone rotated – protected void onPause(); called when still visible but focus is lost – protected void onResume(); called when focus is set AFTER being completely obscured When overriding methods, super class’ version MUST be called

Example protected void onResume() { super.onResume(); //Code goes here //Clear fields, set focus, restart sensor //listeners, etc. }

Additional information Sending information back – When one Activity finishes, activity can be sent back to the Activity that started it as follows: In the original Activity, 2 methods are needed – startActivityForResult (Intent data, int requestCode); must be called to open Activity » any non-negative integer can be used for requestCode – onActivityResult(int requestCode, int resultCode, Intent data) must be implemented » Called when other Activity exits – just before onResume() requestCode is same code from above resultCode is sent from closing Activity data stores any data that was sent back

Additional information Continued from previous slide – In the opened Activity, 1 method is needed setResult(int resultCode, Intent data) must be called prior to finish() – any integer can be used for resultCode » Activity.RESULT_CANCELED » Activity.RESULT_OK » other – data stores any data to be sent back

Sample Code In original Activity public void openActivityAndWaitForResults() { Intent i = new Intent(this, SecondActivity.class); i.putExtra("StringValue", "Coming to you"); startActivityForResult(i, 1); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { Toast.makeText(this, "From second activity: " + requestCode + " " + resultCode + " " + data.getStringExtra("InfoBack"), Toast.LENGTH_LONG).show(); } In opened Activity public void closeActivityAndSendInfoBack () { Intent output = new Intent(); output.putExtra("InfoBack", "Back at you!"); setResult(7, output); finish(); }