Friday, June 7, 2013

Android 1: Lesson 4

Lesson 4: Java Language
INTRODUCTION
In this lesson you will be learning how to understand and use Java and how it will make your app work

LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Learning how to connected your 'main_activity.xml' to your Java
2. Understanding what each piece of code does in Java

LEARNING SEQUENCE

Required Reading
Read the following:
Introduction To Development Environment
·        Eclipse
·        Android
·        Activity-Google site
Resources
View the following: 
1.      Eclipse
2.      Android Development
Assignments 

  1. Java is a complicated language, but it is very efficient when used correctly
  2. First we’ll start with creating a new class in the 'src' folder, open the 'src' folder and you should see the package: 'com.example.(name of your app)', and inside that you'll see the 'MainActivity.java' class. Double click on the class and it will open
  3. Here, you'll see (from the top down) the package name. 3 imports. a public class. and 2 overrides
  4. The imports are what make Java efficient and fast. Java has a massive library of different things it can do, but only if you import it to the app so it knows how
  5. The android 'import android.os.bundle' is what allows it to work in the android API
  6. 'import android.os.Activity' is where all the actual java happens.
  7. 'public class' means that it is open to the users, and the class defines a variable within the class
  8. inside the 'public class' are the overrides. One of them has 'protected void' and the other has 'public boolean'
  9. protected means that it can be accessed by the other classes that get related to it
  10. boolean, inside the other override, is a primitive type of object, using less memory (RAM) to run than the more complicated Boolean, with a captial B. Java is very fragile when it comes to capitalization.
  11. onCreate is what actually runs when the app opens. Java runs in a very specific way. It first scans your code for the onCreate method, than runs from there, as seen on the Google website about Activities http://developer.android.com/reference/android/app/Activity.html
  12. Right now, the Java isn't doing anything with your app and doesn't have the following pieces of code, but you will be adding them next lesson. You have to assign each thing in the interface to a piece of code in Java
  13. For the TextView, it will be assigned the title of 'display', which allows it to get changed and altered by different pieces of Java
  14. You then can assign the buttons to individual pieces of code, cause you don't want them doing the same thing. Making one of the buttons 'add' and the other 'sub'
  15. 'int' tells the Java what it's going to be doing. if you assign 'counter' to the 'int', then the Java will know what you're doing and that it will be adding or subtracting one from the display