90 likes | 110 Views
Explore the Android.util.Log class and understand its usage for debugging. Learn about the MVC (Model View Controller) design pattern and its implementation in an Android project. Review Java language concepts and explore the power of Android Studio for developing robust and debuggable applications.
E N D
Plan for today • Toward debugging and understanding • Today: android.util.Log • Next week: debugger • Reviewing the onCreate, onStart, onX methods of an Android Activity • What happens when you rotate your phone? • MVC: Model View Controller: project • Reviewing Java concepts
android.util.Log • https://developer.android.com/reference/android/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?
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";
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
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
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-view-or-controller-to-view
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
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();
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