sharedpreferences

Shared Preferences in Xamarin.forms

北慕城南 提交于 2019-12-25 18:37:03
问题 I have tried to save login value as true if user has logged in once by using Application.Current.Properties["isLoggedIn"] = "true"; but its not working. If i remove my app from background it again shows the login page but if user is logged in it should show the next page. 回答1: When using 'Application Properties Dictionary' you have to keep in mind few things: According to the official documentation: 'The Properties dictionary is saved to the device automatically'. However, if you want to

How to valid sharedpreference value in android?

人盡茶涼 提交于 2019-12-25 18:24:57
问题 I am checking all these at splashscreen activity, So I am giving this, SharedPreferences spf = getSharedPreferences("myprfs", Context.MODE_PRIVATE); SharedPreferences.Editor spe = spf.edit(); String name = spf.getString("name",""); String id = spf.getString("id",""); String class = spf.getString("class",""); String roll = spf.getString("roll",""); spe.commit(); if((spe != null) && (name != null) && (id != null) && (class != null) && (roll != null)){ Intent i = new Intent(Startpage.this

android context and sharedpreferences

偶尔善良 提交于 2019-12-25 14:01:18
问题 I am trying to get context to run async sharedpreferences. Tried to get context with: public class MainActivity2 extends Activity implements OnClickListener { public MainActivity2(final Context context) { this.context = context; } private Context context; //....rest of class..... } But the app crashes when that it is included. But need something like that to get to sharedpreferences: class CreateUser extends AsyncTask<String, String, String> { // .....rest of .... @Override protected String

How to save RadioButton status with SharedPreference?

两盒软妹~` 提交于 2019-12-25 09:26:05
问题 This is the app view: and here is my activity code: public class Quiz extends AppCompatActivity { public static int point; public static int i = 0; RadioGroup radioGroup; public static int totalPoint =0; int arrValues[]={0,0,0,0}; int iPosition=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); i = 0; final RadioButton radioButton1 =(RadioButton) findViewById(R.id.number_1); final RadioButton

How to save cropped image uri in shared Preference

时间秒杀一切 提交于 2019-12-25 08:58:03
问题 I have selected an image and cropped it. But I want to save the cropped image uri in shared preference so that it can be showed later. I know how to save in shared preference, but the problem key is "how I can get the image URL of the cropped image" ........................ Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); // code for crop image intent.putExtra("crop", "true"); intent.putExtra("aspectX", 0); intent.putExtra("aspectY", 0);

Android - Shared Preferences crashes on some devices.

柔情痞子 提交于 2019-12-25 08:25:32
问题 I have this exception that I get in my crash reports from Android: java.lang.NoSuchMethodError: android.content.SharedPreferences$Editor.apply at com.problemio.ProblemioActivity.first_time_check(ProblemioActivity.java:231) at com.problemio.ProblemioActivity.onCreate(ProblemioActivity.java:47) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) at android.app.ActivityThread

set app background from gallery

半世苍凉 提交于 2019-12-25 08:17:31
问题 I've got an app using shared preferences to set the background from a few pre-determined images, but I'd like to allow the user to be able to pick an image from their gallery. How can I do this? Code below: int bak; int em; int lo; int lay; SharedPreferences data; public static String filename = "bg"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); lo = R.layout.main; data = getSharedPreferences(filename, 0); lay = data.getInt("lout", lo);

How do I set counter in SharedPreferences to save and retrieve data from TextView with button click

安稳与你 提交于 2019-12-25 07:50:08
问题 I have a problem with shared preferences for my Android app. It saves data and also retrieves but wont work with counter. When I click the button, it increments by 0.0005 in TextView , so SharePref must be saved in button event. Now when I restart the app it retrieves it but now on clicking button it gets same as counter does. After restarting app then after clicking it gets back as counter starts. It means that shared preferences data is somehow lost after clicking button. public class

Accessing static SharedPreference variable directly VS through Getter function

大城市里の小女人 提交于 2019-12-25 07:49:52
问题 I have static DefaultSharedPreference variable defined as like here: public class Itu extends Application { public static SharedPreferences sharedPreferencesFDefault; @Override public void onCreate() { sharedPreferencesFDefault = PreferenceManager.getDefaultSharedPreferences(this); } public static SharedPreferences getSharedPreferencesItu(){ return sharedPreferencesFDefault; } } (1. way) When i access it directly from some Activity, it clears sharedPreference: ((Itu) getApplication())

How to refresh/Update Serialize Java Object in sharedPreferences

流过昼夜 提交于 2019-12-25 07:41:30
问题 For storing the serilaizable java object i m using below code if(sharedpreferences.getString(ComplexObjectXMl,"")!=null) { Serializer serializer = new Persister(); MyObject example = null; try { example = serializer.read(MyObject .class, sharedpreferences.getString(ComplexObjectXMl,"")); } catch (Exception e) { e.printStackTrace(); } Intent i1 = new Intent(FirstActivity.this, SecondActivity.class); startActivity(i1); } new MyAsyncTask().execute(); In MyAsyncTask i m storing the