sharedpreferences

Getting “cannot resolve method” error when trying to implement getSharedPreferences in Android Studio

元气小坏坏 提交于 2019-12-20 09:39:43
问题 I'm trying to create a class KeyValueDB which stores methods for interacting with SharedPreferences, however I'm running into a problem just defining the class. All I want the constructor to do is store a sharedPreferences object with the correct filename, but I'm getting a "cannot resolve method 'getSharedPreferences(java.lang.String,int)' I am passing a String and an int... I'm not sure what I'm doing wrong. Appreciate any help! package com.farmsoft.lunchguru.utils; import android.content

How can I share data between Two Android Apps using Shared Preferences?

非 Y 不嫁゛ 提交于 2019-12-20 07:48:57
问题 I have Two Apps, App1 and App2. I want to save data in App1 using shared preference and access in App2 and vice versa. I'm able to save data in App1 and access in App2 but not the opposite. This is what I'm doing now : In Manifest: android:sharedUserId="any string" android:sharedUserLabel="@string/any_string" In App1: SharedPreferences prefs = getSharedPreferences("demopref",Context.MODE_PRIVATE); SharedPreferences.Editor editor =prefs.edit(); editor.putString("demostring", strShareValue);

Android App crashes immediately when preferences screen is started

时光毁灭记忆、已成空白 提交于 2019-12-20 07:35:38
问题 I have been working on a preferences screen for an app, and I haven't even gotten it to display the screen before it crashes. I have examined several tutorials about shared preferences and my code resembles theirs, but nothing has worked. I think the problem is in my preferences.xml file, because I commented out everything except the opening of the XML file in my PreferenceActivity. Here is my preferences.xml file: <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http:/

save android theme using shared preferences

天大地大妈咪最大 提交于 2019-12-20 07:28:26
问题 Hello I am trying to save a theme with shared preferences. When the user clicks a button with a certain theme I want that theme to be set as default and saved so when they reopen the app its still that new theme. Main Activity: /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.onActivityCreateSetTheme(this); setContentView(R.layout.activity_main); findViewById(R.id.button1).setOnClickListener

Saving high scores in Android game - Shared Preferences

為{幸葍}努か 提交于 2019-12-20 07:14:59
问题 Recently I am developing a simple android game. For the scoring part, I have on many websites that shared preferences are best to save the high score. Now, what if I need to save high scores of different levels in my game? I wish to save top three scorers score for each level... 回答1: To save your scores you can do something like this: // prepare the data: put the String values of the scores of the first 3 users // in one String array for each level String[] firstLevelHighscores = new String[]

Android ToggleButton always check

て烟熏妆下的殇ゞ 提交于 2019-12-20 07:08:53
问题 I want to store in SharedPreferences if the toggle button is Checked or uncheck. toggle.setOnCheckedChangeListener(new OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) if(isChecked){ SharedPreferences.Editor editor = getSharedPreferences("SharedPrefName", MODE_PRIVATE).edit(); editor.putBoolean("check", true); editor.commit(); } else { SharedPreferences.Editor editor = getSharedPreferences("SharedPrefName", MODE_PRIVATE).edit(); editor

All keys in SharedPreferences return same value

怎甘沉沦 提交于 2019-12-20 07:08:46
问题 I am using Shared preferences for the first time and getting errors. my code is like this : public class MainActivity extends Activity { static final String ONE = ""; static final String TWO = ""; private static SharedPreferences mSharedPreferences; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences.Editor edi = mSharedPreferences.edit(); edi.putString(ONE, "1"); edi.putString(TWO, "2"); edi

Splash Screen Causes MenuItems not to appear

天涯浪子 提交于 2019-12-20 06:28:07
问题 I've built a splash screen that loads a (splash) activity and then starts another activity and it works fine. (I've attached it below - it's called SPLASH 1) I created another splash screen to replace this one which is supposed to only run once - then after creating a SharedPreferences boolean it is supposed to load another activity. Everything seems fine with this but now when it loads the new activity, none of the menuitems appear. I have no idea what changed in SPLASH 2 - but something in

Windows 8 - Android's SharedPreferences in Windows 8?

倾然丶 夕夏残阳落幕 提交于 2019-12-20 06:25:20
问题 You know SharedPreferences in Android, values that won't be killed even when the apps is closed and can be retrieved back once the apps is restarted again. How do I do this in Windows 8? I tried official tutorial straight from microsoft website http://msdn.microsoft.com/en-us/library/windows/apps/hh986968.aspx. However, it works only in simulator, doesn't work when I run it in Local Machine. Can any windows expert 来源: https://stackoverflow.com/questions/12759641/windows-8-androids

Problem in Shared Preferenced in LoginScreen. Flutter

浪尽此生 提交于 2019-12-20 06:08:06
问题 help and explain to me in detail please how can I modify my code. I am beginner in Flutter and now I am doing tasks, the essence of which is the use of Shared Preferenced in the Login Screen and saving the user data in FireBase. When the user first entered the data, he entered the Home screen, but when the user exits the application and tries to log in again, it should be that he does not need to enter the password and login again. Also, I knocked out such an error import 'package:flutter