Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local storage workshop #5

Open
wants to merge 7 commits into
base: local-storage-workshop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update SharedPreferences key
Yenei committed Oct 28, 2022
commit e8019b5dccc89d37af48161085a56f7e680e8679
5 changes: 5 additions & 0 deletions app/src/main/java/com/ascedncorp/androidbasic/Constant.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ascedncorp.androidbasic

object Constant {
const val GLOBAL_INPUT_CACHE_KEY = BuildConfig.APPLICATION_ID + ".input"
}
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ class MainFragment: Fragment() {
apply()
}
sharedPreferences?.edit()?.apply {
putString(MainActivity.INPUT_TEXT_KEY, binding.edittext.text?.toString() ?: "")
putString(Constant.GLOBAL_INPUT_CACHE_KEY, binding.edittext.text?.toString() ?: "")
apply()
}
requireActivity().supportFragmentManager.beginTransaction()
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ class SecondActivity : AppCompatActivity() {
)
// The SharedPreferences will be shared to the whole application.
val sharedPreferencesInput = getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE).getString(
MainActivity.INPUT_TEXT_KEY,
Constant.GLOBAL_INPUT_CACHE_KEY,
getString(R.string.second_activity_text)
)
binding.tvSharedPreferences.text = String.format(