-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
330dc34
commit 506f569
Showing
5 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/androidmadhav/litmemes/MySIngleton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.androidmadhav.litmemes | ||
|
||
import android.content.Context | ||
import com.android.volley.Request | ||
import com.android.volley.RequestQueue | ||
import com.android.volley.toolbox.Volley | ||
|
||
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 | ||
} | ||
} | ||
} | ||
private 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) | ||
} | ||
} |