android-sharedpreferences

Storing list of position in sharedPreferences, and retrieve in another activity

寵の児 提交于 2021-02-08 03:44:53
问题 I want to do similar like this, I have used cardview with recyclerview. I added favourite button cardview below you can see the full code. In recyclerview adapter I print the Toast as per position and its working fine, now I need to save the int value of position in shared Preferences in arraylist and display those arraylist in next intent. This is my recyclerview adapter public void onBindViewHolder(NameViewHolder holder, final int position) { holder.textView.setText(names.get(position)

getApplicationContext() outside onCreate to upload an image

霸气de小男生 提交于 2021-01-29 08:27:24
问题 I want to upload a image to the server. But I need to send with it the username from the user that is sending the image. I have the username record in SharedPreferences, so I think I could get it: public class UploadRequest extends StringRequest { private static final String REGISTER_REQUEST_URL = "http://160.128.0.10/up.php"; private Map<String, String> params; public UploadRequest(String image, String name, Response.Listener<String> listener){ super(Method.POST, REGISTER_REQUEST_URL,

How to save data by using SharedPreferences in a Fragment

為{幸葍}努か 提交于 2020-11-30 02:13:35
问题 I'm having a problem with saving data permanently. It should be simple, I'm sending data to another Fragment and it works perfectly, however, I have no idea how to save data. I tried something, but I was wondering if you could help me out. In my code, I'm sending a data to another Fragment by pushing a Button. So this is the code: package com.example.mskydraw.notetech; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4

How to save data by using SharedPreferences in a Fragment

試著忘記壹切 提交于 2020-11-30 02:13:06
问题 I'm having a problem with saving data permanently. It should be simple, I'm sending data to another Fragment and it works perfectly, however, I have no idea how to save data. I tried something, but I was wondering if you could help me out. In my code, I'm sending a data to another Fragment by pushing a Button. So this is the code: package com.example.mskydraw.notetech; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4

How to save data by using SharedPreferences in a Fragment

风流意气都作罢 提交于 2020-11-30 02:12:57
问题 I'm having a problem with saving data permanently. It should be simple, I'm sending data to another Fragment and it works perfectly, however, I have no idea how to save data. I tried something, but I was wondering if you could help me out. In my code, I'm sending a data to another Fragment by pushing a Button. So this is the code: package com.example.mskydraw.notetech; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4

How to get value of SharedPreferences android

女生的网名这么多〃 提交于 2020-11-29 09:58:10
问题 I'm trying to use SharedPreferences here is what i do public void StoreToshared(Object userData){ SharedPreferences mPrefs = getPreferences(MODE_PRIVATE); SharedPreferences.Editor prefsEditor = mPrefs.edit(); Gson gson = new Gson(); String json = gson.toJson(userData); Log.d("data", " Setup --> "+json); prefsEditor.putString("userinfo", json); prefsEditor.commit(); } Log.d result is like this Setup --> {"nameValuePairs":{"userData":{"nameValuePairs":{"phone":"089688xxxxxxx", "username":

clear the value of sharedpreferences

心不动则不痛 提交于 2020-08-26 09:34:13
问题 i am kind of new to android programming , i am designing a program that has login page and main page.When i sign in for the first time with a username and password, i created a sharedpreferences to remember that username and whenever i enter program , it skips login page and redirects me to main page.What i want to do is, when i press logout button in login page ,i want sharedpreferences forget the value of username in my database(it wont delete it from database) and force me to login me

What's the difference between getDefaultSharedPreferences() and getPreferences()?

空扰寡人 提交于 2020-01-27 23:26:27
问题 I'm currently taking the "Developing Android Apps" Udacity course. In the "Lesson 3: New Activities and Intents > Use SharedPreferences" segment, the instructor asked me to dig around the Android Developer site for how to get the user preferences from SharedPreferences . However, I found it different between the official documentation and the course's solution. The Udacity course's solution says, to grab a SharedPreferences instance for the PreferenceActivity , you should call: