This file contains hidden or 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
// 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 |
This file contains hidden or 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
// 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 |
This file contains hidden or 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
// 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 |
This file contains hidden or 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
val myStrKey = stringPreferencesKey("myStrKey") | |
val myLongKey = longPreferencesKey("myLongKey") | |
val myIntKey = intPreferencesKey("myIntKey") |
This file contains hidden or 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
private val settingsDataStore by preferencesDataStore(name = "app_settings") |
This file contains hidden or 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
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) |
This file contains hidden or 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
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) |
This file contains hidden or 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
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(); |
This file contains hidden or 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
if (reviewInfo != null) { | |
val reviewflow = reviewManager!!.launchReviewFlow(this, reviewInfo!!) | |
reviewflow.addOnCompleteListener { | |
Toast.makeText( | |
applicationContext, | |
"In App Rating complete", | |
Toast.LENGTH_LONG | |
).show() | |
} | |
} else { |
This file contains hidden or 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
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 | |
} | |
} |