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

Slides:



Advertisements
Similar presentations
Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Advertisements

Programming with Android: Calculator Example
Programming with Android: Activities and Intents
Programming with Android: Activities
Programming with Android: Network Operations
Programming with Android: Module Overview
0 - 0.
Addition Facts
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Notifications, Threads, Services
Programming with Android: System Architecture
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
Addition 1’s to 20.
Test B, 100 Subtraction Facts
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.
Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Android Projects Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione 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.
Programming with Android: Activities
Android 02: Activities David Meredith
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Android Fragments.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Programming with Android: System Architecture
Programming with Android: System Architecture
Programming with Android: Android Fragments Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Android Fragments A very brief introduction Android Fragments1.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Programming with Android: The Google Maps Library Slides taken from Luca Bedogni Marco Di Felice.
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 Programming Lecture 6
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Android – Fragments L. Grewe.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
Fragment Android Club Agenda Fragment Static fragment Dynamic fragment ViewPager.
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
Class on Fragments & threads. Fragments fragment is a modular section of an activity, which has its own lifecycle, receives its own input events, and.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
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.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Activity and Fragment.
Activities, Fragments, and Events
Fragment ?.
Fragments: Introduction
Android 3: Fragments: API Guide
CS499 – Mobile Application Development
Mobile Application Development BSCS-7 Lecture # 6
Android 16: Fragments: Tutorial
Mobile Applications (Android Programming)
Activities and Intents
Widgets & Fragments Kalin Kadiev Astea Solutions AD.
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Android 15: Fragments: API Guide
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
CIS 470 Mobile App Development
Chapter 9: Fragments.
Activities and Intents
CIS 470 Mobile App Development
Mobile Programming Dr. Mohsin Ali Memon.
Activities and Fragments
Activities, Fragments, and Intents
Android Sensor Programming
Presentation transcript:

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

Luca Bedogni, Marco Di Felice – Android for Tablets 2 Outline Android for Tablets: Fragments Transactions Android for Tablets: Fragments Lifecycle Android for Tablets: Fragments Layout Android for Tablets: Fragments Creation Android for Tablets: Fragments Design Philosophy Android for Tablets: A Case Study Android for Tablets: Fragments Back State

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Application Case Study Option1 Option2 LIST of Wireless Networks Detected Statistics Net0 -123dbm channel 2 WEP Net1 -93dbm channel 1 NONE Net2 -93dbm channel 2 WPA Channel0 CHn Option Panel Sub- Activity Sub- Activity

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragments Fragment A portion of the user interface in an Activity. Practically, a Fragment is a modular section of an Activity. DESIGN PHILOSOPHY Structure an Activity as a collection of Fragments. Reuse a Fragment on different Activities … Introduced from Android 3.0 (API Level 11)

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragments Design Philosophy EXAMPLE: Structuring an Application using multiple Activities.

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragments Design Philosophy EXAMPLE: Structuring an Application using 1 Activity and 2 Fragments.

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Transactions EXAMPLE: Using Fragments on Different Devices (Smartphone/Tab)

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Creation To define a new Fragment create a subclass of Fragment. public class MyFragment extends Fragment { …} Has its own lifecycle (partially connected with the Activity lifecyle) Has its own layout (or may have) Can receive its own input events Can be added or removed while the Activity is running. PROPERTY of a Fragment:

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Lifecycle Several callback methods to handle various stages of a Fragment lifecycle: onCreate() called when creating the Fragment. onCreateView() called when it is time for the Fragment to draw the user interface the first time. onPause() called when the user is leaving the Fragment.

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Creation onCreateView() must return the View associated to the UI of the Fragment (if any) … public class ExampleFragment extends Fragment public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) { return inflater.inflate(R.layout.example_fragment, container, false); }

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Lifecycle The lifecycle of the Activity in which the Fragment lives directly affects the lifecycle of the Fragment. onPause (Activity) onPause (Fragment) onStart (Activity) onStart (Fragment) onDestroy (Activity) onDestroy (Fragment) Fragments have also extra lifecycle callbacks to enable runtime creation/destroy.

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Adding a Fragment to the UI Specify layout properties for the Fragment as it were a View. <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <fragment android:name="it.cs.android30.FragmentOne" android:layout_width="wrap_content" android:layout_height="fill_parent" /> <fragment android:name="it.cs.android30.FragmentTwo" android:layout_width="wrap_content" android:layout_height="fill_parent" />

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Managing Fragments A Fragment can get a reference to the Activity … Activity getActivity() An Activity can get a reference to the Fragment … ExampleFragment fragment=(ExampleFragment) getFragmentManager(). findFragmentById (R.id.example_f ragment) The FragmentManager manages the Fragment associated to the current Activity.

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Managing Fragments In some cases, a Fragment must share an event with the Activity … how to do it? 1.Define a callback interface inside the Fragment 1.Require that the host Activity implements it public interface OnArticleSelectedListener { public void onArticleSelected(Uri uri); … }

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Transactions Fragments can be added/removed/replaced while the Activity is running … Each set of changes to the Activity is called a Transaction. Transaction can be saved in order to allow a user to navigate backward among Fragments when he clicks on the Back button.

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Transactions FragmentManager man=getFragmentManager(); FragmentTransaction transaction=man.beginTransaction(); FragmentExample newFragment=new FragmentExample(); transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackState(null); transaction.commit(); 1. ACQUIRE an instance of the FRAGMENT MANAGER 2. CREATE new Fragment and Transaction 3. SAVE to backStack and COMMIT

Luca Bedogni, Marco Di Felice – Android for Tablets (c) Luca Bedogni Android: Fragment Transactions A Transaction is not performed till the commit … If addToBackStack() is not invoked the Fragment is destroyed and it is not possible to navigate back. If addToBackStack() is invoked the Fragment is stopped and it is possible to resume it when the user navigates back. popBackStack() simulate a Back from the user.