class MySingleton constructor(context: Context) {
companion object {
@Volatile
private var INSTANCE: MySingleton? = null
fun getInstance(context: Context) =
INSTANCE ?: synchronized(this) {
INSTANCE ?: MySingleton(context).also {
INSTANCE = it
}
}
}
val requestQueue: RequestQueue by lazy {
// applicationContext is key, it keeps you from leaking the
// Activity or BroadcastReceiver if someone passes one in.
Volley.newRequestQueue(context.applicationContext)
}
fun <T> addToRequestQueue(req: Request<T>) {
requestQueue.add(req)
}
}
4. 사용하기
val url = "http://www.example.com"
// Formulate the request and handle the response.
val stringRequest = StringRequest(Request.Method.GET, url,
Response.Listener<String> { response ->
// Do something with the response
},
Response.ErrorListener { error ->
// Handle error
})
val queue = MySingleton.getInstance(this.applicationContext).requestQueue
queue.add(stringRequest)
starts the placeholder. If you want to insert a literal%character, then you must insert two of them :%%.
Index ':'
takes theIndex-th element in the argument array as the element to insert. Ifindexis omitted, then the zeroth argument is taken.
'-'
tellsFormatto left-align the inserted text. The default behaviour is to right-align inserted text. This can only take effect if theWidthelement is also specified.
Width
the inserted string must have at leastWidthcharacters. If not, the inserted string will be padded with spaces. By default, the string is left-padded, resulting in a right-aligned string. This behaviour can be changed by the usage of the'-'character.
'.' Precision
Indicates the precision to be used when converting the argument. The exact meaning of this parameter depends onArgType.
usage: screencap [-hp] [-d display-id] [FILENAME]
-h: this message
-p: save the file as a png.
-d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.