Programming with Android: Activities

Slides:



Advertisements
Similar presentations
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Advertisements

Programming with Android: Calculator Example
Programming with Android: Activities
Services. Application component No user interface Two main uses Performing background processing Supporting remote method execution.
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
CE881: Mobile and Social Application Programming Simon M. Lucas Quiz, Walkthrough, Exercise, Lifecycles, Intents.
Cosc 5/4730 Android: “Dynamic” data.. Saving Dynamic data. While there are a lot of ways to save data – Via the filesystem, database, etc. You can also.
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.
CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna.
Fragments: Introduction Fragments were introduced in Android 3.0 to support flexible and dynamic UI designs represent portions of an application’s user.
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
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.
Android Mobile computing for the rest of us.* *Prepare to be sued by Apple.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
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.
Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
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.
Android Application Lifecycle and Menus
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
Android Fragments. Slide 2 Lecture Overview Getting resources and configuration information Conceptualizing the Back Stack Introduction to fragments.
Activity and Fragment.
Programming with Android:
Basic Activities and Intents
Activities, Fragments, and Events
Fragment ?.
Mobile Application Development BSCS-7 Lecture # 6
CS499 – Mobile Application Development
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.
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
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.
Adding Functionality to the App Tip Calculator App Activity and the Activity Lifecycle onCreate is called by the system when an Activity.
Activities and Intents
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Activity Lifecycle.
Activities and Intents
Objects First with Java
SE4S701 Mobile Application Development
Activities and Fragments
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Programming with Android: Activities Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna 1 1

Activity Outline: What is started by the device It contains the application's informations Has methoda to answer certain events An application could be composed of multiple activities 2

Create a class that is a subclass of Activity Creating an activity Create a class that is a subclass of Activity Implement callback methods OnCreate(): Initialize SetContentView() 3

Activity lifecycle 4

Activity lifecycle 5

Need to implement every single method? No! Activities Need to implement every single method? No! It depends on the application complexity Why it is important to understand the activity lifecycle? So your application does not crash (or do funny things) while the user is running something else on the smartphone So your application does not consume unnecessary resources So the user can safely stop your application and return to it later 6

Activities states Resumed Paused Stopped The activity is in the foreground, and the user can interact. Paused The activity is partially overlayed by another activity. Cannot execute any code nor receive inputs. Stopped Activity is hidden, in the background. It cannot execute any code. 7

Activity lifecycle OnCreate() Called when the activity is created Should contain the initialization operations Has a Bundle parameter If onCreate() succesfull terminates, it calls onStart() 8

Activity lifecycle OnStart() Called when onCreate() terminates Called right before it is visible to user If it has the focus, then onResume() is called If not, onStop() is called 9

Activity lifecycle OnResume() Called when the activity is ready to get input from users Called when the activity is resumed too If it succesfully terminates, then the Activity is RUNNING 10

Activity lifecycle OnPause() Called when another activity comes to the foreground, or when someone presses back Commit unsaved changes to persistent data Stop cpu-consuming processes Make it fast 11

Activity lifecycle OnRestart() Similar to onCreate() We have an activity that was previously stopped 12

Activity lifecycle OnStop() Activity is no longer visible to the user Could be called because: the activity is about to be destroyed another activity comes to the foreground 13

Activity lifecycle OnDestroy() The activity is about to be destroyed Could happen because: The systems need some stack space Someone called finish() method on this activity Could check with isFinishing() 14

Activity loops Mainly 3 different loops Entire lifetime Between onCreate() and onDestroy(). Setup of global state in onCreate() Release remaining resources in onDestroy() Visible lifetime Between onStart() and onStop(). Maintain resources that has to be shown to the user. Foreground lifetime Between onResume() and onPause(). Code should be light. 15

Activities in the manifest Declare them before running them <activity android:name=".MainActivity" android:label="@string/app_name">     <intent-filter>         <action android:name="android.intent.action.MAIN" />         <category android:name="android.intent.category.LAUNCHER" />     </intent-filter> </activity> Why “MAIN” and “LAUNCHER”? To show the application in the menu 16

Recreating Activities 17

Recreating Activities Android keeps the state of each view Remember to assign unique Ids to them So, no code is needed for the “basic” behavior What if I want to save more data? Override onSaveInstanceState() and onRestoreInstanceState() static final String STATE_SCORE = "playerScore"; @Override public void onSaveInstanceState(Bundle savedInstanceState) {     savedInstanceState.putInt(STATE_SCORE, mCurrentScore);     super.onSaveInstanceState(savedInstanceState); } 18

Recreating Activities @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState); // Always call the superclass first        if (savedInstanceState != null) {         // Restore value of members from saved state         mCurrentScore = savedInstanceState.getInt(STATE_SCORE);     } else {         // Probably initialize members with default values for a new instance     } } public void onRestoreInstanceState(Bundle savedInstanceState) {     super.onRestoreInstanceState(savedInstanceState);     mCurrentScore = savedInstanceState.getInt(STATE_SCORE); 19

Activity: Conclusions Activities should be declared in the Manifest Extend the Activity class Code wisely Put your code in the right place Optimize it Test even on low-end devices 20