skip to Main Content

Android Studio – How to use sharedpref.edit() only once

I have a code where I called sharedPref.edit() and sharedPref.apply() multiple times. How to make convert it to call only once. if (success) { val data = response.getJSONObject("data") sharedPreferences.edit().putBoolean("isLoggedIn", true).apply() sharedPreferences.edit() .putString("user_id", data.getString("user_id")).apply() sharedPreferences.edit().putString("name", data.getString("name")) .apply() sharedPreferences.edit().putString("email", data.getString("email")) .apply() sharedPreferences.edit()…

VIEW QUESTION

Android Studio – Can't change editText input from string to float

package com.example.tipcalculator import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.TextView import kotlin.text.toFloat as kotlinTextToFloat class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) supportActionBar?.hide() val tenPerTip: Button = findViewById(R.id.tenPerTipButton) val fifteenPerTip: Button = findViewById(R.id.fifteenPerTipButton) val…

VIEW QUESTION

Android Studio – AES Encryption in Kotlin

The Android docs give the following snippet for how to encrypt a message in AES: val plaintext: ByteArray = ... val keygen = KeyGenerator.getInstance("AES") keygen.init(256) val key: SecretKey = keygen.generateKey() val cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING") cipher.init(Cipher.ENCRYPT_MODE, key) val ciphertext: ByteArray =…

VIEW QUESTION
Back To Top
Search