sharedpreferences

How to store a default value in SharedPreferences

怎甘沉沦 提交于 2020-01-07 09:30:08
问题 I am creating a restaurant app that consist of members to register/login into the system and non-members to view the menu by skipping registering/login process. My homescreen has menu (for non-members to view directly), sign-in and sign-up buttons (for members to register/login). I want to store a default phoneId and password into SharedPreference to let 'non-members' to view the menu by skipping login/registering process(p/s auto-login for only non-members ). However, I always face

How to store a default value in SharedPreferences

时光总嘲笑我的痴心妄想 提交于 2020-01-07 09:30:07
问题 I am creating a restaurant app that consist of members to register/login into the system and non-members to view the menu by skipping registering/login process. My homescreen has menu (for non-members to view directly), sign-in and sign-up buttons (for members to register/login). I want to store a default phoneId and password into SharedPreference to let 'non-members' to view the menu by skipping login/registering process(p/s auto-login for only non-members ). However, I always face

Shared preferences value not updating the second time android

帅比萌擦擦* 提交于 2020-01-07 06:44:13
问题 I have used a Broadcast receiver to change the value of a variable inside my fragment every 24 hours. Since the value of the variable gets reinitialized to previous initialization when the fragment restarts I have used shared preferences to save the value every time so that it does not reinitialize again and again. The problem is that the value is changed once and is not updating again. so if the value is 10 it changes to 11 but then does not go to 12. This is the broadcast receiver public

Android: SharedPreference errors after force close

拥有回忆 提交于 2020-01-07 05:39:18
问题 I'm getting some weird effects after I force close my app. When the app is closed with finish(), everything is fine. I have some variables saved in a sharedPreferences so when the app is loaded again, it can restore those variables into the UI. However, if I force close the app and THEN try to continue where it had left off, some variables start "acting funny". By that I mean (in onCreate) I check to see if a string, loaded from the sharedPreferences, equals a value (crunched down version):

Introduction of Sharedpreference in tap counter app causes app crash

£可爱£侵袭症+ 提交于 2020-01-07 04:22:42
问题 I'm trying to do a basic tap counter app that stores counter value to sharedpreference. App works as normal as a tap counter without sharedpreference when I run it, but when I introduce sharedpreference, the app crashes. ~ MainActivity ~ public class MainActivity extends AppCompatActivity { public static final String PREFS = "examplePrefs"; Button btn_tap, btn_trophy, btn_reset; TextView tv_tapped, tv_times, tv_tap1; private int counter = 0; @Override protected void onCreate(Bundle

Android using shared preference and Dispatcher activity, to get back to the last activity (after reboot the phone)

人走茶凉 提交于 2020-01-06 19:57:14
问题 I'm using a Shared Preferences to save the state of my application to be able to get to the last activity before my Android Handphone got re-boot-ed. My purpose is when Android system manage the memory and push out my apps, when users re-enter to the apps, they will get to the last Activity and screen of my apps. And this is some of my code : First is DispatcherActivity.java : > package com.lm.rosary; > > import android.app.Activity; import android.content.Intent; import > android.content

findpreference undefined type

廉价感情. 提交于 2020-01-06 19:43:49
问题 I am trying to set a value to a ListPreference and always get the error message: The method findPreference(String) is undefined for the type new DialogInterface.OnClickListener(){} This is my code: ListPreference lp = (ListPreference) findPreference("enableTranslations"); lp.setValue(""); Thanks 回答1: You simply call findPreference in wrong place (in OnClickListener). Call it in method of class that has findPreference method (PreferenceManager or PreferenceActivity) or on object of such type.

Shared Preference not holding session (Android K)

情到浓时终转凉″ 提交于 2020-01-06 16:24:52
问题 I am having a project which uses Shared Preferences for Session Management. Everything is fine with the code but what really annoying is that the app is holding the session in Android Lollipop and above but unfortunately it is not holding the same for Android Kitkat and below. The session is lost whenever the app is closed and you have to lo in again. Following are the codes, I am using: Session.java package com.saptak.disputesession; import android.content.Context; import android.content

Changing background colour with SharedPreference in Android

旧巷老猫 提交于 2020-01-06 08:14:10
问题 I want to change the background color of my app with a button. It should switch between two colors, for this I used SharedPreference, but >I don't know yet how to store the boolean for switching.. I got this: public void method1(View view) { SharedPreferences settings = getSharedPreferences(PREFS, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("modus", !modus); editor.commit(); if (settings.getBoolean("modus", false)) { int i = Color.GREEN; LinearLayout layout =

How to get Facebook user Profile (id,name,email and picture) and use in other activity by sharedpreferences [closed]

扶醉桌前 提交于 2020-01-06 06:28:29
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I have an app that uses Facebook for login and then, go to another activity. First of all, I check the correct login and works fine. Then, I saved the dates of my profile on a Arraylist of string and then, save on sharedpreferences. This is the code of my First Activity (login activity) import android.content