Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.

Similar presentations

Presentation on theme: "CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013."— Presentation transcript:

1 CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013

2 Today 1.App Fundamentals and Skeleton (last week) 1.Architecture Diagram (today) 2.Activity (today) 1.Function 2.Lifecycle 3.Coding Assignment 3.Services (today) 1.Function 2.Lifecycle 3.Coding Assignment 4.Content Providers (week 37/3) 5.Intent and Intent Filters (week 38/4) 6.Processes and Threads (week 39/5) 7.Permission (week 40/6) 8.App Widgets (week 40/6) 9.Android Manifests (week 40/6)

3 Architecture Diagram

4 What are the functions of an activity? 1.Interact in most case with user 2.Usually applications have several activities 3.Each is implemented as a subclass of base Activity class 4.Creates the window to place UI 1.setContentView(R.layout.home_activity); 5.Methods 1.protected void onCreate(Bundle savedInstanceState); // initialize 2.protected void onStart(); //activity visible 3.protected void onRestart(); //before activity becomes visible 4.protected void onResume(); // activity visible after being paused 5.protected void onPause(); // another activity becomes visible 6.protected void onStop(); // activity not visible 7.protected void onDestroy(); // cleanup and destroy activity

5 What is the lifecycle of an activity?

6 Coding Assignment (5 min) 1.Start Android Developer Tools 2.Create a new Project with one Activity 3.Define all six methods in that activity

7 What are the functions of a service? 1.Runs in the background – what does it mean? 2.Each is implemented as a subclass of base Service class 3.Examples – Music, TCP, REST, and other long running operations… 4.Methods 1.public void onCreate() // initialize 2.public void onStartCommand() // started 3.public void onBind() // activity to service communication 4.public void onDestroy() // cleanup resources 5.public void stopService() // stop service

8 Service - Function Services must be declared in AndroidManifest.xml Remember to update the string resource file!

9 What is the service lifecycle? 1.Does a Service have Lifecycle? 1.Arguably no, since there is no interaction with the user, internally yes. 2.Who can start a service? 1.Services, Receivers, and Activities 3.How do you start a service? – Intent i= new Intent(getApplicationContext, MyAppService.class); – i.putExtra(“key", “value"); – getApplicationContext.startService(i);

10 Coding Assignment (5 min) Create a Service class Add 5 methods Start that Service through the Activity and pass a key/value pair Print out value/pair using activity on console

11 Questions What are the four layers of the Android Architecture Stack? What is the function of an activity? What are the four states of an activity? What are the six methods that change the state of an activity? What is a Service? What are the 5 methods that implement a service? What is the difference between Activity and Service? Who can start service?

12 References nts/activities.html nts/activities.html nts/services.html nts/services.html Professional Android 4 Application Development (Reto Meier, 2012)

Download ppt "CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013."

Similar presentations

Ads by Google