Skip to content

Instantly share code, notes, and snippets.

View wajahatkarim3's full-sized avatar
:octocat:
Subscribe to my newsletter: remotekaro.substack.com

Wajahat Karim wajahatkarim3

:octocat:
Subscribe to my newsletter: remotekaro.substack.com
View GitHub Profile
// Get the DataStore object
private val settingsDataStore by preferencesDataStore(name = “app_settings”)
// Get the keys
val myStrKey = stringPreferencesKey("myStrKey")
// Read the values through coroutine scopes
lifecycleScope.launch {
settingsDataStore.data.map { pref ->
// Read the values here
// Get the DataStore object
private val settingsDataStore by preferencesDataStore(name = “app_settings”)
// Get the keys
val myStrKey = stringPreferencesKey("myStrKey")
// Write the values through coroutine scopes
lifecycleScope.launch {
settingsDataStore.edit { pref ->
// Write the values here
// Get the DataStore object
private val settingsDataStore by preferencesDataStore(name = “app_settings”)
// Get the keys
val myStrKey = stringPreferencesKey("myStrKey")
// Read the values through coroutine scopes
lifecycleScope.launch {
settingsDataStore.data.map { pref ->
// Read the values here
val myStrKey = stringPreferencesKey("myStrKey")
val myLongKey = longPreferencesKey("myLongKey")
val myIntKey = intPreferencesKey("myIntKey")
private val settingsDataStore by preferencesDataStore(name = "app_settings")
val preferences = this.getSharedPreferences("SOME_NAME", Context.MODE_PRIVATE)
// Get the Editor of SharedPreferences
val editor = preferences.edit()
// Save values through put*() methods
editor.putString("myStrKey", “Some String Value Goes Here”)
editor.putLong("myLongKey", 12L)
editor.putInt("myIntKey", 10)
editor.putDouble("myDoubleKey", 2.0)
val preferences = this.getSharedPreferences("SOME_NAME", Context.MODE_PRIVATE)
// Reading the values from Preferences
val myStr = preferences.getString("myStrKey", "DEFAULT_STR")
val myLong = preferences.getLong("myLongKey", 0)
val myInt = preferences.getInt("myIntKey", 1)
val myDouble = preferences.getDouble("myDoubleKey", 0.0)
class MainActivity : AppCompatActivity() {
var reviewManager: ReviewManager? = null
var reviewInfo: ReviewInfo? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getReviewInfo();
if (reviewInfo != null) {
val reviewflow = reviewManager!!.launchReviewFlow(this, reviewInfo!!)
reviewflow.addOnCompleteListener {
Toast.makeText(
applicationContext,
"In App Rating complete",
Toast.LENGTH_LONG
).show()
}
} else {
val request: Task<Review Info?> = reviewManager.requestReviewFlow()
request.addOnCompleteListener { task ->
if (task.isSuccessful) {
// We got the ReviewInfo object
val reviewInfo = task.result
} else {
// There was some problem, log or handle the error code.
@ReviewErrorCode val reviewErrorCode = (task.getException() as TaskException).errorCode
}
}