sharedpreferences

How to save score to SharedPreferences then update it?

≡放荡痞女 提交于 2019-12-22 00:43:03
问题 I have an app which shows the total earnings of stars in the MainActivity as textview. I want to do is input 0 if the app is run for the first time. Then afterwards as I finish a level and earn some stars (like currentScore + 50 = newScore) it will be redirected to MainActivity with the newScore textView. This is my MainActivity where the the textview shows the score public class MainActivity extends Activity { private static TextView txt_stars; @Override protected void onCreate(Bundle

How to access shared preference boolean value from another class

三世轮回 提交于 2019-12-21 22:53:16
问题 I have created a radio group which contains two buttons, I can select one and save it, it works fine, still stored after closing the app. What I want to do is use the value of the radio buttons in another class. Here is my settings class which contains the shared preferences code: public class Settings extends Activity { private String settingsTAG = "AppNameSettings"; private SharedPreferences prefs; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method

Android Using SharedPreferences to save and retrieve values - Counter

孤人 提交于 2019-12-21 21:49:08
问题 Hello I am new to android and actually i am developing a application whereby the user would be clicking on a button and the button should record the click event - the counter should be incremented at each time the button is clicked. The button would be displayed in one activity and once the user has clicked the button, another activity would be displayed whereby the results would be shown. Actually i am having problems in assigning the sharedPreferences to the button and then displaying it

Android - save Object to SharedPreferences and get it anywhere in the app

邮差的信 提交于 2019-12-21 20:14:20
问题 In my app I have a custom User class which holds some regular data (name etc...). I need to save that object and get it anywhere and anytime in other pages of the app. I made a helper class public final class GeneralMethods with many methods which I use a lot (static, of course). In order to save the data Im using Gson library. I made this method: public static void saveData(Context con, String variable, String data) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences

Android SharedPreferences Example

吃可爱长大的小学妹 提交于 2019-12-21 19:45:36
问题 I'm trying to learn SharedPreferences, but I'm getting an error. My layout has one button that reeacts to the method doThis This is my java: package com.example.sharedprefs; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity { int i = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R

Resource/Code path changing for pkg on Android App update

本秂侑毒 提交于 2019-12-21 17:52:39
问题 If i update my app with a new version, the sharedPreferences are gone. LogCat says: Package de.xxx.yyy codePath changed from /data/app/de.xxx.yyy-1.apk to /data/app/de.xxx.yyy-2.apk; Retaining data and using new The Package is the same as before. The changes of the manifest-file are: android:versionCode="6" -> android:versionCode="7" android:versionName="1.6.000" -> android:versionName="1.8" and added Permission: <uses-permission android:name="android.permission.VIBRATE" /> Why the new

Android Internal storage VS Shared preferences

丶灬走出姿态 提交于 2019-12-21 10:12:30
问题 Is there a difference between storing service authentication token in Internal storage (in file) and in Shared Preferences? 回答1: Not really, it's a matter of convenience. With shared preferences you don't need to handle file IO. 回答2: shared preference will be better than to store credential in file, to open and readfile is tedious compare to use of share preference 回答3: Although both can be private types. The conventional approach is: if you have small key value pair go with shared preference

Android Internal storage VS Shared preferences

纵饮孤独 提交于 2019-12-21 10:12:09
问题 Is there a difference between storing service authentication token in Internal storage (in file) and in Shared Preferences? 回答1: Not really, it's a matter of convenience. With shared preferences you don't need to handle file IO. 回答2: shared preference will be better than to store credential in file, to open and readfile is tedious compare to use of share preference 回答3: Although both can be private types. The conventional approach is: if you have small key value pair go with shared preference

Writing Singleton Class To Manage Android SharedPreferences

≡放荡痞女 提交于 2019-12-21 04:25:06
问题 i am trying to write a singleton class to oversee all operations involving shared preferences. I have 3 preference files, general, settings, and temp I want to be able to use this class to write a preference of a given type, for example: stg_full_screen: true // as boolean This is what i have done so far: import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; public class SharedPrefManager extends Activity { // Globals private int GENERAL = 1000

Logout clear SharedPreferences

强颜欢笑 提交于 2019-12-21 03:57:04
问题 I have login page that save username and password to Shared Preferences. I have another Activity class that include logout button. I want to clear Shared Preferences when click logout button. Problem is I dont get the SharedPreferences from this class. How can I get the SharedPreferences ? LoginPage public class MainActivity extends Activity { public SharedPreferences.Editor loginPrefsEditor; public SharedPreferences loginPreferences; private Boolean saveLogin; @Override protected void