Download slides4

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Plan for today

Toward debugging and understanding



Reviewing the onCreate, onStart, onX
methods of an Android Activity


Today: android.util.Log
Next week: debugger
What happens when you rotate your phone?
MVC: Model View Controller: project

Reviewing Java concepts
Compsci 290.3/Mobile, Spring 2017
4.1
android.util.Log


https://developer.android.com/reference/an
droid/util/Log.html
Why is this android.util and not java.util?


Path and package name
Where does Log write data? Why would
you use Log rather than System.out?


What about what's on your phone?
Can your App "phone home" with log info?
Compsci 290.3/Mobile, Spring 2017
4.2
Review log changes
protected void onStart() {
super.onStart();
Log.d(DTAG,"onStart " + getIDs());
}
private String getIDs(){
return String.format("myId = %d, instance = %d",
myInstanceID,ourInstances);
}
private int myInstanceID;
private static int ourInstances;
private static String DTAG = "MainActivityDebug";
Compsci 290.3/Mobile, Spring 2017
4.3
Java Language Concepts

Static variables are per class, not per object



If you create 100 Pixel objects, each has it's own
r,g,b values, e.g., in myRed, myGreen, myBlue
Total number of pixels ever created would be a
static variable, not an instance variable!
Use formatted strings, e.g., String.format
rather than concatenating strings

Android is smart about String + v.
StringBuilder
Compsci 290.3/Mobile, Spring 2017
4.4
Concepts for next project

Review Activity, Layout, Resources


Model examples we've done, use Android
Developer documentation, read and read and
read
You'll create a "quiz". Could be anything,
Buzzfeed, Duolingo TinyCards, something
simple



Source of quiz
UI of taking quiz
Persistence of quiz
Compsci 290.3/Mobile, Spring 2017
4.5
Model View Controller

(aka MVC) This object-oriented design
pattern is ubiquitous

Main idea is that controller mediates between
model and view, M and V loosely coupled

http://stackoverflow.com/questions/29594105/mvc-is-it-model-to-viewor-controller-to-view
Compsci 290.3/Mobile, Spring 2017
4.6
Activity, Views, MVC and Project

Where are Views created, how are they
accessed?



Activity accesses widgets via findViewById, use
the power of Android Studio to help
Instance variables access state across methods,
e.g., myLeftButton
What should the source of questions be?



Not in Activity, why not?
Not in XML file, why not?
Loose coupling, High cohesion
Compsci 290.3/Mobile, Spring 2017
4.7
Android Concepts


https://gitlab.oit.duke.edu/ola/quizmaster
How do you make a custom/app icon?



Where do you store images?
Why are there so many version of images?
What is a toast?
Toast.makeText(
MainActivity.this,
"left click, total = "+ourButtonCount,
Toast.LENGTH_SHORT).show();
Compsci 290.3/Mobile, Spring 2017
4.8
Java Concepts

What is a constructor? What is a method?
What is an instance variable?

What do access modifiers mean: public,
private, protected?


Java vs. what we're doing wrt protected
Inner classes and how they work, toward
creating an Interface
Compsci 290.3/Mobile, Spring 2017
4.9
Related documents