Tutorial by Examples: at

package com.example; import android.os.Bundle; import android.support.annotation.Nullable; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; public class ExampleActivity extends Activity { @Override protected void onCreate(@Nullable final ...
If you need to produce a JSON string with a value of null like this: { "name":null } Then you have to use the special constant JSONObject.NULL. Functioning example: jsonObject.put("name", JSONObject.NULL);
With this class: class ObjectMemberVsStaticMember { static int staticCounter = 0; int memberCounter = 0; void increment() { staticCounter ++; memberCounter++; } } the following code snippet: final ObjectMemberVsStaticMember o1 = new ObjectMemberVsStati...
It is helpful to filter the logcat output because there are many messages which are not of interest. To filter the output, open the "Android Monitor" and click on the drop down on the top-right and select Edit Filter Configuration Now you can add custom filters to show messages which ar...
The AppCompat support library provides themes to build apps with the Material Design specification. A theme with a parent of Theme.AppCompat is also required for an Activity to extend AppCompatActivity. The first step is to customize your theme’s color palette to automatically colorize your app. I...
A Toolbar is a generalization of ActionBar for use within application layouts. While an ActionBar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. It can be added by performing t...
The Arrays.asList() method can be used to return a fixed-size List containing the elements of the given array. The resulting List will be of the same parameter type as the base type of the array. String[] stringArray = {"foo", "bar", "baz"}; List<String> stringL...
Updating the state of a Swing component must happen on the Event Dispatch Thread (the EDT). The javax.swing.Timer triggers its ActionListener on the EDT, making it a good choice to perform Swing operations. The following example updates the text of a JLabel each two seconds: //Use a timer to updat...
private visibility allows a variable to only be accessed by its class. They are often used in conjunction with public getters and setters. class SomeClass { private int variable; public int getVariable() { return variable; } public void setVariable(int variable) { ...
To create an IntentService, create a class which extends IntentService, and within it, a method which overrides onHandleIntent: package com.example.myapp; public class MyIntentService extends IntentService { @Override protected void onHandleIntent (Intent workIntent) { //Do so...
Set up Android Studio Start by setting up Android Studio and then open it. Now, you're ready to make your first Android App! Note: this guide is based on Android Studio 2.2, but the process on other versions is mainly the same. Configure Your Project Basic Configuration You can start a new ...
All Javadoc comments begin with a block comment followed by an asterisk (/**) and end when the block comment does (*/). Optionally, each line can begin with arbitrary whitespace and a single asterisk; these are ignored when the documentation files are generated. /** * Brief summary of this class...
All Javadoc comments begin with a block comment followed by an asterisk (/**) and end when the block comment does (*/). Optionally, each line can begin with arbitrary whitespace and a single asterisk; these are ignored when the documentation files are generated. /** * Brief summary of method, end...
A Pattern can be compiled with flags, if the regex is used as a literal String, use inline modifiers: Pattern pattern = Pattern.compile("foo.", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); pattern.matcher("FOO\n").matches(); // Is true. /* Had the regex not been compiled case...
All Javadoc comments begin with a block comment followed by an asterisk (/**) and end when the block comment does (*/). Optionally, each line can begin with arbitrary whitespace and a single asterisk; these are ignored when the documentation files are generated. /** * Fields can be documented as ...
You can get the value of other primitive data types as a String using one the String class's valueOf methods. For example: int i = 42; String string = String.valueOf(i); //string now equals "42”. This method is also overloaded for other datatypes, such as float, double, boolean, and ...
If your computation produces some return value which later is required, a simple Runnable task isn't sufficient. For such cases you can use ExecutorService.submit(Callable<T>) which returns a value after execution completes. The Service will return a Future which you can use to retrieve the r...
The ScheduledExecutorService class provides a methods for scheduling single or repeated tasks in a number of ways. The following code sample assume that pool has been declared and initialized as follows: ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); In addition to the nor...
Java SE 5 It is possible to create package-level documentation in Javadocs using a file called package-info.java. This file must be formatted as below. Leading whitespace and asterisks optional, typically present in each line for formatting reason /** * Package documentation goes here; any docu...
Maps provide methods which let you access the keys, values, or key-value pairs of the map as collections. You can iterate through these collections. Given the following map for example: Map<String, Integer> repMap = new HashMap<>(); repMap.put("Jon Skeet", 927_654); repMap.p...

Page 5 of 442