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)

Android: Failed to invoke private android.net.Uri() with no args

北战南征 提交于 2021-02-07 18:47:24
问题 I am saving my arraylist of custom model into shared preference using Gson Storing code: ArrayList<DownloadProgressDataModel> arrayList = getArrayListFromPref(downloadProgressDataModel); SharedPreferences.Editor prefsEditor = getSharedPreferences("APPLICATION_PREF", MODE_PRIVATE).edit(); Gson gson = new Gson(); String json = gson.toJson(arrayList); prefsEditor.putString("DownloadManagerList", json); prefsEditor.apply(); } Retrieving ArrayList<DownloadProgressDataModel> arrayList; Gson gson =

MODE_PRIVATE in sharedpreferences error

喜欢而已 提交于 2021-02-07 11:33:13
问题 I use this code as a BroadcastReceiver , but it says that MODE_PRIVATE cannot be resolved to a variable broadcastreceiver public class anyNewService extends BroadcastReceiver { String uid,text; int c=1; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub SharedPreferences settings =getSharedPreferences("CASPreferences", MODE_PRIVATE); uid = settings.getString("uid", ""); anyNewCheker(); } public void anyNewCheker() { HttpClient httpclient = new

MODE_PRIVATE in sharedpreferences error

元气小坏坏 提交于 2021-02-07 11:33:07
问题 I use this code as a BroadcastReceiver , but it says that MODE_PRIVATE cannot be resolved to a variable broadcastreceiver public class anyNewService extends BroadcastReceiver { String uid,text; int c=1; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub SharedPreferences settings =getSharedPreferences("CASPreferences", MODE_PRIVATE); uid = settings.getString("uid", ""); anyNewCheker(); } public void anyNewCheker() { HttpClient httpclient = new

Android: Sort data retrieved from SharedPreferences

牧云@^-^@ 提交于 2021-01-29 21:17:29
问题 I am trying to store data in Android. I am using the SharedPreferences . And I am retrieving these data by using: SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE); Map<String, ?> keys = myPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { Log.i("map values", entry.getKey()); //some code } EDIT: But data retrieved are not in the same order as they were inserted. How to get the same order? 回答1: Copy the resulting Map into an implementation

Null content Shared Preferences in Kotlin

☆樱花仙子☆ 提交于 2021-01-29 20:26:18
问题 I'm developing an app that uses Shared Preferences, so I created a class only for this, but when I launch the app I get this error: 2020-06-03 14:51:50.124 32656-32656/com.go.experimental E/AndroidRuntime: FATAL EXCEPTION: main Process: com.go.experimental, PID: 32656 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.go.experimental/com.go.experimental.AccesoActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content

Android: Sort data retrieved from SharedPreferences

淺唱寂寞╮ 提交于 2021-01-29 18:29:33
问题 I am trying to store data in Android. I am using the SharedPreferences . And I am retrieving these data by using: SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE); Map<String, ?> keys = myPrefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { Log.i("map values", entry.getKey()); //some code } EDIT: But data retrieved are not in the same order as they were inserted. How to get the same order? 回答1: Copy the resulting Map into an implementation

SharedPreferences not working on real device FLUTTER

蹲街弑〆低调 提交于 2021-01-29 17:42:05
问题 I used SharedPreferences to make remember username and password to log in next time without asking a password. It was working well when I debug using my real device with USB cable. But it's not working in my device when I build APK and install it. I don't know what I'm missing. I save data in login page like this` Future<Null> loginUser(isLogin, name, fac, year, gender) async { final SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString('Name', name); prefs

check value exists or not using EncryptedSharedPreferences android

旧街凉风 提交于 2021-01-29 15:26:20
问题 I use the EncryptedSharedPreferences to store value while login...i want to change text in navigation drawer of home activity so when user is loggedin it will show logout else it will show login navigation drawer Loginactivity:-------- sharedPreferences = EncryptedSharedPreferences.create( "secret_shared_prefs", masterKeyAlias, baseContext, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM ) as

Sending token and Id to Server

岁酱吖の 提交于 2021-01-29 06:12:04
问题 I am trying to develop a webview app that uses JSinterface to get the user_id. what I am trying to do is send two values to my server, user_id and FCM token,onpause(). i am getting and saving the fcm token inside my onCreate() like that. FirebaseInstanceId.getInstance().getInstanceId() .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { @Override public void onComplete(@NonNull Task<InstanceIdResult> task) { if (!task.isSuccessful()) { Log.w(TAG, "Failed", task.getException())