Chien-Chung Shen cshen@udel.edu Manifest and Activity Chien-Chung Shen cshen@udel.edu.

Slides:



Advertisements
Similar presentations
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
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.
Android 101 Application Fundamentals January 29, 2010.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
ANDROID PROGRAMMING MODULE 1 – GETTING STARTED
CS378 - Mobile Computing Anatomy of an Android App and the App Lifecycle.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
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.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
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.
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
CS378 - Mobile Computing Intents.
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.
Overview of Android Application Development
Android - Broadcast Receivers
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.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Google map v2.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Appendix.
Mobile Applications (Android Programming)
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Mobile Application Development BSCS-7 Lecture # 2
Android Application Development 1 6 May 2018
Activity and Fragment.
Activities, Fragments, and Events
MAD.
Activities and Intents
Android 9: The Activity Lifecycle
Anatomy of an Android App and the App Lifecycle
The Android Activity Lifecycle
Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast.
Mobile Device Development
ANDROID UI – FRAGMENTS UNIT II.
Android Programming Lecture 9
CS5103 Software Engineering
CIS 470 Mobile App Development
Anatomy of an Android App and the App Lifecycle
CMPE419 Mobile Application Development
Android Topics Android Activity Lifecycle and Experiment Toast
Activities and Intents
Activities and Intents
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Activities and Fragments
Chapter 5 Your Second Activity.
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Chien-Chung Shen cshen@udel.edu Manifest and Activity Chien-Chung Shen cshen@udel.edu

Android Manifest (1) Configure Android application describe components and settings of an Android app in AndroidManifest.xml specify additional metadata for the application, e.g., icons and version number read by Android system during installation of the app Declare components in the manifest file All activities, services and content provider components of the app must be statically declared in this file Specify Permissions (for network access)

Android Manifest (2) Application Component <application> section defines metadata for the app and is also a container for declaring app’s Android components Component <activity> tag defines an activity component the name attribute points to class, which (if not fully qualified) is relative to the package defined in the package attribute

Android Manifest (3) Activity intent filter tells Android runtime that this activity should be registered as a possible entry point into the app and made available in the launcher of Android system <action android:name="android.intent.action.MAIN” /> defines that it can be started <category android:name="android.intent.category.LAUNCHER” /> tells Android system to add the activity to the launcher <activity android:name=".MainActivity367” // point to the Java class android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

Example (1) <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.chienchungshen.android367" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.INTERNET" /> ……. </manifest>

Example (2) <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity367" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>

Resource ID and R.java Every resource gets an ID assigned by Android build system The ./build/generated/source/r/debug/com/example/chienchungshen/Android367/app directory contains the R.java references file which contains these generated static integer values If you add a new resource file, the corresponding reference is automatically created in a R.java file. Manual changes in the R.java file are not necessary and will be overwritten by the tooling The Android system provides methods to access the corresponding resource files via these IDs to access a String with the R.string.yourString ID in your source code, you would use getString(R.string.yourString) method defined on the Context class

Activity An Android component (other components are service, content provider, and broadcast receiver) An activity is the visual representation of an Android application An Android application can have several activities Activities use views and fragments to create the user interface and to interact with the user

Activity As a user navigates through, out of, and back to your app, Activity instances in your app transition between different states in their lifecycle. For instance, when your activity starts for the first time, it comes to the foreground of the system and receives user focus during this process, Android system calls a series of lifecycle callback methods on the activity in which you set up the user interface and other components if the user performs an action that starts another activity or switches to another app, the system calls another set of lifecycle callback methods on your activity as it moves into the background (where the activity is no longer visible, but the instance and its state remains intact)

Activity Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity. For example, if you're building a streaming video player, you might pause the video and terminate the network connection when the user switches to another app when the user returns, you can reconnect to the network and allow the user to resume the video from the same spot

Start an Activity Unlike other programming paradigms in which apps are launched with a main() method, Android system initiates code in an Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle Java code: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); }

Lifecycle Callbacks During the life of an activity, Android system calls a core set of lifecycle callback methods in a sequence similar to a step pyramid each stage of the activity lifecycle is a separate step on the pyramid as the system creates a new activity instance, each callback method moves the activity state one step toward the top top of the pyramid is the point at which the activity is running in the foreground and the user can interact with it

Lifecycle Callbacks As the user begins to leave the activity the system calls other methods that move the activity state back down the pyramid in order to dismantle the activity n some cases, the activity will move only part way down the pyramid and wait (such as when the user switches to another app), from which point the activity can move back to the top (if the user returns to the activity) and resume where the user left off

“Healthy” Activity Lifecycle Does not crash if the user receives a phone call or switches to another app while using your app Does not consume valuable system resources when the user is not actively using it Does not lose the user's progress if they leave your app and return to it at a later time Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation

“Static” States An activity may transition between different states Only three of these states can be static, i.e., the activity can exist in one of only three states for an extended period of time Resumed - the activity is in the foreground and the user can interact with it (Running state) Paused - the activity is partially obscured by another activity and the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen. The paused activity does not receive user input and cannot execute any code Stopped - the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code

Start an Activity When user selects your app icon from the Home screen, the system calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or "main") activity This is the activity that serves as the main entry point to your app's user interface <activity android:name=".MainActivity367" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

MainActivity367 public class MainActivity367 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the user interface layout for this Activity // The layout file is defined in res/layout/activity_main_activity367.xml setContentView(R.layout.activity_main_activity367); } ……

Start Another Activity In activity_a.xml <Button android:id="@+id/btn_start_b" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/btn_start_b_label » android:onClick="startActivityB"  /> In ActivityA.java public void startActivityB(View v) { Intent intent = new Intent(ActivityA.this, ActivityB.class); startActivity(intent); }