1 / 94

Welcome to Android!

Welcome to Android!. Let’s Review What we know about the web. Structure is _________ Presentation is ___________ Behavior is ___________. HTML. CSS. Javascript. In Android. Structure is _________ Presentation is ___________ Behavior is ___________. XML. HTML. XML. CSS. Java.

efia
Download Presentation

Welcome to Android!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome to Android!

  2. Let’s Review What we know about the web • Structure is _________ • Presentation is ___________ • Behavior is ___________ HTML CSS Javascript

  3. In Android • Structure is _________ • Presentation is ___________ • Behavior is ___________ XML HTML XML CSS Java Javascript

  4. Web Review • HTML has specific elements for certain jobs • <p> for non editable text • <h1-h6> header • <li> for list items • HTML has specific elements to contain other elements • <div> • <span> • <ol>/<ul>

  5. Android • Android has certain elements for certain jobs as well. • In android, we call these elements VIEWS • Android also has specific elements to contain other elements • In android, we call these elements View Groups

  6. When the HTML document get loaded what object is created? <body> <divid="box1"class="box">1</div> <divid="box2"class="box">2</div> <divid="box3"class="box">3</div> <divid="box4"class="box">4</div> <body> body div#box1 div#box2 div#box3 div#box4

  7. Android XML Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout>

  8. Android XML Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> LinearLayout TextView Button In Android Lingo, the DOM is known as the View Hierarchy

  9. Web Review Using the DOM, how do we find elements? • ID • Class • Tag • Attribute • Traversing the DOM tree (firstChild, parent, children, etc.)

  10. In Android We find views by • ID • Traversing the View Hierarchy

  11. What is Android? • A software stack for mobile devices that includes an operating system, middleware, and key applications. • Uses large parts of the Java API • Doesn’t use Swing or AWT • Uses XML to declare layouts • Supports SQLite • Awesome!

  12. Android OS Versions

  13. Android Toolkit • Eclipse is the premier IDE for developing Android. • Integrates the Android SDK for easy building, virtual device creation, and more. • Android apps can be built with Apache Ant; therefore, you could use any text editor of your preference.

  14. Eclipse Hotkeys

  15. Eclipse Perspectives • Eclipse “Perspectives” determine the visible actions and views within a window/tab. • For android there are 3 important “Perspectives”: • Java • Debugging • DDMS

  16. Java Perspective • This is the window where you will do the majority of your coding.

  17. Debugging Perspective • This is the default debugging tool built into Eclipse. Very similar to other debuggers (Netbeans, Visual Studio, etc). • Allows the ability to set break points in code and pause the application’s execution and step through code line by line. • Allows the ability to view a variable’s value(s) in real time, step into functions, etc.

  18. Debugging Perspective

  19. DDMS Perspective • Usually the place for “advanced” features. • Provides info for: • Devices • Shows connected android devices and emulators • Emulator Control • Change network state, speed, latency • Spoof calls or SMS text messages • Set location of phone • Logcat • Outputs messages that you print out using the Log class along with other system messages such as stack traces when exceptions are thrown.

  20. DDMS Perspective

  21. Logging Messages in Android • System.out.println does not work like in regular Java programs. • Instead make use of the Log class.

  22. Logging in Android • Log.d(String tag, String msg) – Send a DEBUG log message. • Log.e(String tag, String msg) – Send an ERROR log message. • Log.i (String tag, String msg) – Send an INFO log message. • Log.v (String tag, String msg) - Send a VERBOSE log message. • Log.w(String tag, String msg) – Send a WARN log message.

  23. Logging in Android • In the DDMS Perspective, inside the Logcat window, you can filter Log messages. • You can filter log messages to reduce “noise” and only see certain types of Log messages.

  24. Filtering Log Messages • By TAG – the first parameter of Log method • By type: • DEBUG • ERROR • INFO • VERBOSE • WARN

  25. Log Example This Log message could be filtered either by adding a filter for “INFO” Log messages or by adding a filter for the “HelloWorld” tag.

  26. Log Documentation • See http://developer.android.com/reference/android/util/Log.html for more details.

  27. What makes an Android App? Most Apps Consists of • Android manifest • Activities • Views • Event logic for user interaction • XML for defining layout, widgets, shapes, and colors • OpenGL ES 1.1 or 2.x GLSurfaceView or Skia Canvas (android.graphics) if creating your own widgets. • SQL Lite database • JSON or XML for data to and from servers

  28. Main components of an Android App • Android Manifest • Activities • Views • Application Resources • Application Logic

  29. Android Manifest • Presents essential information about the application to the Android system. The system must have this info before running any of the application’s code. 1

  30. Android Manifest’s role • Names the java package for the application. • Declares permissions the application must have in order to operate. • Access to the internet • Access user’s contact data • Read/write to system settings. • Etc.

  31. Android Manifest’s role • Declares the minimum level of the Android API the application requires to run. • Specify application icon and title • Describes the components of the application • Activities • Services • Broadcast receivers • Content provider

  32. Android Manifest Example

  33. Android Manifest Documentation • http://developer.android.com/guide/topics/manifest/manifest-intro.html

  34. What is an Android Activity • An activity is a single, focused thing that the user can do. • Activities in the system are managed as an activity stack (LIFO). • An application consists of at least 1 Activity, but can have many.

  35. Activity • Android Apps don’t have the main() paradigm. • Unlike C, C++, Java, etc. • Instead, Android uses an Activity for the code execution starting point of an application. • Activities have an important life cycle which every Android developer should know!!! 2

  36. Activity Lifecycle

  37. Activity Lifecycle onCreate() • An activity is created when a user launches an application. • The Activity’s onCreate() is the very first method called. Think of it as main(). • Use this method for basic startup logic that should happen only once for the entire lifecycle.

  38. onCreate()startup logic • Create User Interface components dynamically or from resources. • Initialize class scope variables.

  39. Activity Lifecycle onStart() • Your application becomes visible

  40. Activity Lifecycle onResume() • The activity is visible and running • Your activity will remain in this state until: • A new application starts (receive a phone call) • User navigates to a new activity (back key) • The device screen turns off • Use this method to resume anything that was stopped or paused.

  41. Activity Lifecycle onPause() • Happens when your activity is partially hidden. (Pop-up Window) • As long as your activity is partially visible but not in focus, you’re paused. • Use this method to pause ongoing actions (video, music, animation, etc.), save state, and release system resources.

  42. Activity Lifecycle onStop() • Happens when your activity is no longer visible. • Use this method to • release all system resources that aren’t needed while hidden • write information to a database

  43. Resume from Pause & Restart from Stopped

  44. Activity Lifecycle onStop() • While your activity is stopped, your application is kept in memory. • If the OS runs out of memory while your application is stopped, it may be destroyed.

  45. Stop to destroy

  46. Activity Lifecycle onDestroy() • Called when the system destroys your activity. • By now you should have released all application resources in onPause() and onStop(), so you shouldn’t have to do much here. • This method is not guaranteed to be called, so you shouldn’t rely on it.

  47. Activity Lifecycle • Once your activity is destroyed, all hope is not lost. • When your app is paused you have the opportunity to save temporary state into a blob. • When the system tries to resume your application, the blob is used to restore your application to the state is was in when it was paused.

  48. Recreated after getting destroyed

  49. Views • Views are “widgets” that appears on the screen. • Similar to HTML element • Each View has predetermined characteristics, use cases, and attributes. 3

  50. Two Basic View Types View • Base class for widgets • Used to create interactive UI components. • Button • Textfield • Image ViewGroup • Base class for layouts. • Serve as containers that hold others Views or ViewGroups • Define layout properties. • Have unique characteristics for how they position children (grid, horizontally, vertically, list, etc)

More Related