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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Manifest File, Intents, and Multiple Activities. Manifest File.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
Android Development (Basics)
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
1 Mobile Computing Monetizing An App Copyright 2014 by Janson Industries.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Mobile Programming Lecture 6
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Android - Broadcast Receivers
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Linking Activities using Intents How to navigate between Android Activities 1Linking Activities using Intents.
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Activity Android Club Agenda Hello Android application Application components Activity StartActivity.
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.
Android App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Mobile Programming Midterm Review
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
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.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity.
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Android and s Ken Nguyen Clayton state University 2012.
Lecture 2: Android Concepts
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
Android Programming.
Lab7 – Appendix.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Lecture 2: Android Concepts
Android Application Development 1 6 May 2018
several communicating screens
Linking Activities using Intents
Android – Event Handling
Android Introduction Hello World.
Android Notifications
CS499 – Mobile Application Development
Android Introduction Camera.
CIS 470 Mobile App Development
Many thanks to Jun Bum Lim for his help with this tutorial.
Mobile Computing With Android ACST 4550 Android Database Storage
Activities and Intents
CIS 470 Mobile App Development
Android Notifications
Activities and Intents
Lecture 2: Android Concepts
Objects First with Java
Chapter 5 Your Second Activity.
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

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 s you! It makes the projects go by much more smoothly

2 Schedule Last time: Android basics Today: Android application development Thursday: Testing (B&B chapter 25) Next week: More testing!! (B&B chapters 26-28)

3

4

5 Android Forms

6 Out-of-the-box View classes Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time pickers Auto-complete Can mostly be placed in Layout using main.xml

7 EditText: “description” EditText: “title” Button: “clear” Button: “save” Spinner: “spinner” TextView

8

<LinearLayout 4 xmlns:android=" 5 android:orientation="vertical" 6 android:layout_width="fill_parent" 7 android:layout_height="fill_parent"> 8 9 <LinearLayout android:orientation="horizontal" 10 android:layout_width="fill_parent" 11 android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" 14 android:layout_height="wrap_content" 15 /> <EditText 18 android:layout_width="wrap_content" 19 android:layout_height="wrap_content" 20 android:layout_weight="1"/> 21 22

10 23 <TextView android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 /> <EditText 29 android:layout_width="fill_parent" 30 android:layout_height="wrap_content" 31 android:layout_weight="1" 32 android:scrollbars="vertical" /> <Spinner android:layout_width="fill_parent" 38 android:layout_height="wrap_content" 39 />

11 40 <LinearLayout android:orientation="horizontal" 41 android:layout_width="fill_parent" 42android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" 47 android:layout_height="wrap_content" /> 48 49<Button android:layout_width="wrap_content" 52 android:layout_height="wrap_content" />

12 Handling user interaction Recall that each View has an onTouchEvent method that is automatically called by Android when the user interacts with the View In the Android View classes, Events are dispatched to registered Listeners depending on the type of action (click, key press, long click, etc.) For Buttons, you can simply use the main.xml file to specify the method used to handle clicks

13 1.Edit the Layout (in main.xml) so that the “Clear” Button's “onClick” attribute is set to the onClearButtonClick method 2.Implement the onClearButtonClick method in your class that extends Activity 3.That method will automatically be called when the user clicks the “Clear” button Button: “clear” EditText: “description” EditText: “title”

14 In main.xml... 40<LinearLayout android:orientation="horizontal" 41android:layout_width="fill_parent" 42android:layout_height="wrap_content"> 43 44<Button 45 46android:layout_width="wrap_content" 47android:layout_height="wrap_content" /> 48 49<Button 50 51android:layout_width="wrap_content" 52android:layout_height="wrap_content" 53android:onClick="onClearButtonClick" /> 54 55

15 In the class that extends Activity... 1 /* 2 * When the Clear button is clicked, this method 3 * gets called. 4 */ 5 public void onClearButtonClick(View view) { 6 7 // get the “title” field by its ID 8 EditText title = (EditText)findViewById(R.id.title); 9 10 // clear it 11 title.setText(""); // same for the “description” field 14 EditText desc = 15 (EditText)findViewById(R.id.description); desc.setText(""); 18 } }

16 Applications with Multiple Activities

17

18 Intents When a new Activity is started, an Intent object is created and passed to that Activity The Intent object contains information about what the Activity is meant to do, and any data it needs in order to do it When the Launcher starts an application, it looks for the Activity with the “MAIN” action

19 AndroidManifest.xml 1 2 <manifest 3 xmlns:android=" 4 package="edu.upenn.cis542" 5 android:versionCode="1" 6 android:versionName="1.0"> 7 8 <application <activity android:name=“LaunchActivity"

20 LaunchActivity ButtonClickActivity

21 In the LaunchActivity class... 1 // request code used in creating the new Activity 2 public static final int ButtonClickActivity_ID = 1; 3 4 public void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 setContentView(R.layout.launch); 7 } 8 9 public void onLaunchButtonClick(View v) { 10 // create an Intent using the current Activity 11 // and the Class to be created 12 Intent i = new Intent(this, ButtonClickActivity.class); // pass the Intent to the Activity, 15 // using the specified request code 16 startActivityForResult(i, ButtonClickActivity_ID); 17 }

22 Review: Starting a new Activity Create an Intent object with a reference to a Context (this) and the Class that represents the new Activity Add any key/value pairs to the Intent's Bundle by calling putExtra Call startActivity or startActivityForResult and pass the Intent and the request code (int)

23

24 In ButtonClickActivity... 1 public void onFinishButtonClick(View view) { 2 // create the Intent object to send BACK to the caller 3 Intent i = new Intent(); 4 5 // put the number of clicks into the Intent 6 i.putExtra(“NUM_CLICKS", num_clicks); 7 setResult(RESULT_OK, i); 8 9 // ends this Activity 10 finish(); 11 }

25 Review: Finishing an Activity Create an Intent object (empty constructor) Call putExtra with key/value pairs or putExtras with a Bundle object (where key/val pairs were set with putString) Call setResult with the result code (usually either RESULT_OK or RESULT_CANCELED) and the Intent Call finish()

26

27 In LaunchActivity... 1 // this method gets called when an Activity finishes 2 protected void onActivityResult(int requestCode, 3 int resultCode, Intent intent) { 4 super.onActivityResult(requestCode, resultCode, intent); 5 6 // the requestCode lets us know which Activity it was 7 switch(requestCode) { 8 case ButtonClickActivity_ID: 9 // get the number of clicks from the Intent object 10 Integer clicks = 11 (Integer)(intent.getExtras().get(“NUM_CLICKS")); // display the pop-up 14 Toast.makeText( 15 this, 16 “Num clicks is " + clicks, 17 Toast.LENGTH_LONG) 18.show(); break; 21 } 22 }

28 Review: Returning from an Activity onActivityResult is called in the calling Activity, with the request code, result code, and Intent object as parameters Use request code to figure out which Activity it is that's returning (in case you created more than one) Use Intent object to get back any “return values”

29 Activity lifecycle

30

31 Words of Wisdom In general, an Activity should be as self-contained as possible E.g., responsible for its own persistence, instead of passing data along to the caller Activity The user may click the “Back” button, and the callee Activity may not finish the way you want it to Look out for null values in the Intent object in the onActivityResult method

32 Android Threads

33 Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in the “main thread” prohibits UI events from being handled This means that any long-running code should run in a background thread However, background threads are not allowed to modify UI elements!

34 How Android threading works Create a class that extends AsyncTask To start the new thread, call the AsyncTask's execute method When execute is called, Android does the following: 1.runs onPreExecute in the main (UI) thread 2.runs doInBackground in a background thread 3.runs onPostExecute in the main (UI) thread

35 1 // this method gets when some button is clicked 2 public void onButtonClick(View view) { 3 new BackgroundTask().execute(editText.getText().toString()); 4 } 5 6 // class that will run in the background 7 // 8 class BackgroundTask extends AsyncTask { 9 10 // automatically called by “execute” 11 protected String doInBackground(String... inputs) { 12 String reply = // do some background stuff return reply; // this gets sent to onPostExecute 14 } // automatically called when doInBackground is done 17 protected void onPostExecute(String result) { 18 // update Views in the UI 19 tv = (TextView)findViewById(R.id.display_view); 20 tv.setText(result); 21 } 22 }

36 “Toast” Notifications

37

38 In the Activity class... 1 public void onCreate(Bundle savedInstanceState) { 2 super.onCreated(savedInstanceState); 3 setContentView(R.layout.main); 4 5 // set the key listener for the title field 6 EditText title = (EditText)findViewById(R.id.title); 7 title.setOnKeyListener(new TabKeyListener()); 8 9 // display a Toast notification with a welcome message 10 Toast.makeText(getApplicationContext(), 11 R.string.welcome_message, 12 Toast.LENGTH_LONG).show(); }

39 For More Information Official documentation: developer.android.com Feel free to use Piazza for Android-related questions when working on your group projects Also, please share any info you find that may be helpful to others