90% of your time as an Android developer will be spent in Android studio.
Java Coding for Android
The convention is constants are written in all CAPS.
Declare a Java Class
https://docs.oracle.com/javase/tutorial/java/concepts/class.html
Java keywords. Reserved symbols that has existing meaning / purpose in Java.
programming https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
Basic Android Development Cheat sheet on Medium
https://medium.com/@ryanstewartalex/basic-android-development-cheat-sheet-58d501dabb3f
Common Android Views Cheat Sheet by Udacity
http://labs.udacity.com/images/Common-Android-Views-Cheat-Sheet.pdf
OOP in Java Android
Use @overide to declare overriding of parent methods.
Use extend to inherit parent methods.
Java strings are immutable, means they cannot be edited despite that indexing is allowed. The entire variable has to be reassigned. StringBuilder is mutable and is used for that purpose.
Pro Tip turn on auto import to automatically import modules.
Variable scope matters. Each function variable will get destroyed if the function returned.
Android studio has left, right (aka side panes) and bottom panes - lots of easy access menu.
Android Getter and Setter Methods
Getter methods are traditionally prefixed with get. E.g. getText
Setter methods are traditional prefixed with set. E.g. setText()
Android Casting and Inheritance
casting inheritance
https://plus.google.com/+KatherineKuanPlus/posts/GyrcP6fEo2v
https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
https://stackoverflow.com/questions/44902651/no-need-to-cast-the-result-of-findviewbyid
Android Log
Example: Log.i("name_of_class_where_error_is_from.java","Your Message Here");
https://developer.android.com/studio/command-line/logcat
Commonly used Android tools
Android Monitor - Android debugging system, output of log, breaks and code step through
Gradle - Gradle tasks that help project build and run correctly. Gradle is the system that is responsible ultimately for building and running Android projects.
Project -
Terminal - provides command line interface
TODO - track todo list in the source file.
Capture - tracks bugs found in connected devices
Event log - display messages related to events and activities like a notification system
Favorites - a favorite list for files
Gradle Console - display information about the Gradle system, display errors, warnings or success message
Message - Display outputs from the Gradle Build System. Display if any problem compiling the application
Structure - Shows high level view of the source file, classes, variables and methods. It's "hyperlinked" : can click and jump to source file.
A temporary message such as a notification is called a
Toast in Android.
Android can use
intent to activate functionality of another app: for example in web browser, you click on share, wanting to send an article using the Gmail app instead.
Common intents in Android
https://developer.android.com/guide/components/intents-common
https://developer.android.com/guide/components/intents-filters#Resolution
public void capturePhoto(String targetFilename) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.withAppendedPath(mLocationForPhotos, targetFilename));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
}
See the code above. if intent.resolveActivity(getPackageManager()) == null is the exception handling.
Android Intent Exception Handling
Run an intent only if it is found in the system and can be resolved.
Android Intent is useful when you want to launch existing Android functionalities such as Camera, Send an Email, and more.
Special formatted data can be written in (Uniform Resource Identifier) URI - structure data in a specific way so that it can be processed by the receiving end. For example tel:415-xxx-xxxx where x is some number between 0-9 is considered a phone number on iPhones. When user tap the URI, a phone call will be made. Similarly on android, tapping an URI linked email address will open up the Gmail app.
Commonly Used Android Methods and Attributes
findViewById returns a View
TextView.setText: change text of a TextView
ImageView.setImageResource: change image url source
onClick attribute: an XML field and an event listener on the android view
Common Android Errors
Android incompatible type error: usually fix by casting e.g. trying to store an int returning function result into a string variable
Android Developer Tools
Android SDK Search Chrome Extension: use this chrome extension to view Android source code
https://plus.google.com/+AndroidDevelopers/posts/1EyxkFnPjmD
You can also click on the view source link by each class name to access the source code in git.
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/TextView.java
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/ImageView.java
Udacity simplified TextView and ImageView class (teaching aid)
https://gist.github.com/udacityandroid/bd550cc8fd37190d85a6
https://gist.github.com/udacityandroid/47592c621d32450d7dbc
Read more here http://www.techotopia.com/index.php/A_Tour_of_the_Android_Studio_User_Interface