-
Notifications
You must be signed in to change notification settings - Fork 0
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
94d81c7
commit 205ba13
Showing
7 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
31 changes: 31 additions & 0 deletions
31
MemeShare/app/src/main/java/com/pratyakshkhurana/funmemes/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,31 @@ | ||
package com.pratyakshkhurana.funmemes | ||
|
||
import android.content.Context | ||
import com.android.volley.Request | ||
import com.android.volley.RequestQueue | ||
import com.android.volley.toolbox.Volley | ||
|
||
//Singleton class is the one , it has only one instance | ||
//so app can call one request at at time | ||
//so we call using singleton and follow singleton pattern | ||
class MySingleton constructor(context: Context) { | ||
companion object { | ||
//volatile to make thread safe, ensure safety | ||
@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) | ||
} | ||
} |