[Solved] How to resolve NullPointerException in SharedPreference? [duplicate]

The most likely cause is because the fragment has not yet attached to the activity. You need to call getActivity() in the fragment’s onActivityCreated() method. void onActivityCreated (Bundle savedInstanceState){ //call getActivity() here } solved How to resolve NullPointerException in SharedPreference? [duplicate]

[Solved] What should I use (sqlite or Shared preferences) to store lat-lng of entire trip locally in android? trip can be very long i.e upto 3 days

What should I use (sqlite or Shared preferences) to store lat-lng of entire trip locally in android? trip can be very long i.e upto 3 days solved What should I use (sqlite or Shared preferences) to store lat-lng of entire trip locally in android? trip can be very long i.e upto 3 days

[Solved] How to pass EditText value in SharedPreferences

You called these functions in onCreate function. You should put theme in a button’s listener button.setOnClickListener(new View.OnClickListener { @Override private void onClick(View view){ // get text from EditText // put text to SharedPreferences } }); When application started, there is nothing in your EditText. 0 solved How to pass EditText value in SharedPreferences

[Solved] How to store an image path in the shared preferences in android?

All you have to do is, convert your image to it’s Base64 string representation: Bitmap realImage = BitmapFactory.decodeStream(stream); ByteArrayOutputStream baos = new ByteArrayOutputStream(); realImage.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] b = baos.toByteArray(); String encodedImage = Base64.encodeToString(b, Base64.DEFAULT); textEncode.setText(encodedImage); SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this); Editor edit=shre.edit(); edit.putString(“image_data”,encodedImage); edit.commit(); and then, when retrieving, convert it back into bitmap: SharedPreferences shre … Read more

[Solved] SharedPreferences Save value of Int in a TextView

I explained where I made changes public class MainActivity extends Activity { Button search; TextView tvRing; //Making sharedpreferences and integers global for ease of use private SharedPreferences prefs; private int redRing, someint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); search = (Button) findViewById(R.id.radar); tvRing = (TextView) findViewById(R.id.ring); //Someint default value is 0 if not … Read more

[Solved] Android Saving JSON response in Sharedpreferences

Use this class for your purpose with files ! Hope it will help you ! public class MyJSON { static String fileName = “myBlog.json”; public static void saveData(Context context, String mJsonResponse) { try { FileWriter file = new FileWriter(context.getFilesDir().getPath() + “https://stackoverflow.com/” + fileName); file.write(mJsonResponse); file.flush(); file.close(); } catch (IOException e) { Log.e(“TAG”, “Error in Writing: … Read more

[Solved] how to save color in sharedpreferences

I hope this code helps you. It can be written in a more beautiful way but I hope you get the idea. //Convert the color to hex, Save it in preferences var myColor = Colors.blue; var hex = ‘#${myColor.value.toRadixString(16)}’; //save Hex value in sharedpreference. //get the hex value from shared preferences and convert it into … Read more

[Solved] how show recently entered text in edit text after entering as suggestion later on using shared preferences?

First convert your EditText->AutoCompleteTextView. add also store shared preferences data into string array list. then after used below code like … String[] countries = getResources().getStringArray(R.array.list_of_countries_name); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries); mAutoCompleteTextView.setAdapter(adapter); mAutoCompleteTextView.setThreshold(1); solved how show recently entered text in edit text after entering as suggestion later on using shared preferences?

[Solved] How to Skip LauncherActivity and call another Activity when application start

You can use SharedPreference for achieving this. You need to implement the logic in your SplashActivity. You need to check whether already logged in or not using the value stored in shared preference and show next activity based on that. In your SplashActivity (Where you launch the login activity), add the logic like: // Retrieving … Read more

[Solved] Shared Preferences saving an int?

The Android Developers documentation is an excellent place to start with any question like this. SharedPreferences can be found here. SharedPreferences is a simple Key-Value pair storage, so if you put an int into your shared preferences as with the key “high score”, then in the future, if you want to get that int, you … Read more

[Solved] How to use shared preference to send data from activity to fragment?

If you insist on shared preference use this code : To save the data private void saveSp(String key , String value){ PreferenceManager.getDefaultSharedPreferences(Context) .edit() .putString(key, value).apply(); } To get your data: PreferenceManager.getDefaultSharedPreferences(Context).getString(“string”, “default”) solved How to use shared preference to send data from activity to fragment?