sharedpreferences

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

假如想象 提交于 2019-12-23 06:40:33
问题 I have got an image path that I want to store in the shared preferences. How do I store the path inside the shared preferences? How can I retrieve the image path from the shared preferences? 回答1: 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

Use SharedPreferences to display popup only once

浪尽此生 提交于 2019-12-23 06:18:22
问题 I have the following code in my onActivityForResult method after I add a contact using an intent. if (mySharedPrefs.getBoolean("settingsPopup", false) == false) { //First time new AlertDialog.Builder(this) .setTitle("Go to settings? ") .setMessage("POPUP") .setNegativeButton("No", null) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent settingsIntent = new Intent(MainActivity.this, Settings.class); startActivity

How to check if a user has already clicked a Button?

删除回忆录丶 提交于 2019-12-23 06:14:15
问题 I have a button in my menu with a “promo code” inside. I need to check if a user already clicked it so I can tell him (the next time he clicks it) “You already redeemed this promo code!” How do I do that? I need only the piece of code where I can check for button clicked. @Override public boolean onOptionsItemSelected(MenuItem item) { boolean clicked = false; switch (item.getItemId()) { case R.id.getcode: SharedPreferences pref = getSharedPreferences("promo", MODE_PRIVATE); boolean activated

Why get data from shared preferences have a delayed?

£可爱£侵袭症+ 提交于 2019-12-23 06:03:40
问题 I have one screen to display data from shared preferences. I already success save and get data from shared preferences. Then I have a flow in one screen like this: If the user clicks that screen, it will check the data from shared preferences. If data is not null / not empty, it will display the data login like user profile, etc. If data is null/empty, it will show a button login. I get the logic for that flow, but the problem is, before data showing in the screen (number 2), it shows button

Why get data from shared preferences have a delayed?

百般思念 提交于 2019-12-23 06:03:13
问题 I have one screen to display data from shared preferences. I already success save and get data from shared preferences. Then I have a flow in one screen like this: If the user clicks that screen, it will check the data from shared preferences. If data is not null / not empty, it will display the data login like user profile, etc. If data is null/empty, it will show a button login. I get the logic for that flow, but the problem is, before data showing in the screen (number 2), it shows button

Getting java.lang.nullPointerException using SharedPreferences

99封情书 提交于 2019-12-23 05:47:03
问题 I am trying to save the date of file parsing, so that when next time user, opens the application, the date can be checked against the last parsing date. I am using shared preference to save the data and retrieve it, but getting error. Here is the code : SharedPreferences settings = getPreferences(0); String today = new Date(System.currentTimeMillis()).toString(); SharedPreferences.Editor edit = settings.edit(); System.out.println("******** Today : " + today); edit.putString("lastdate", today)

Using Shared preferences to send data to another activity

白昼怎懂夜的黑 提交于 2019-12-23 05:09:00
问题 What Have i done :: As you can clearly see i am sending data from BLD_IndividualListOfItems_Starters to ResultActivity using intents... looks like its a collection What i want to achieve :: I want to achieve same output using shared preferences ....that means in BLD_IndividualListOfItems_Starters i want to add the data & in ResultActivity i want to retrieve it using shared preferences What changes in code should i need to make BLD_IndividualListOfItems_Starters.java public class BLD

How to save state of CheckBox after exit?

本小妞迷上赌 提交于 2019-12-23 04:52:45
问题 In my app ,one interface has some checkBoxes,I wish after I exit the interface, the CheckBoxes should maintain the state.So next time I enter it can show what I have done last time.I have used SharedPreferrences to achieve this. checkbox1.setOnCheckedChangeListener(new OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { // TODO Auto-generated method stub Editor editor = getSharedPreferences("syllabus", 0).edit(); editor.putBoolean("cbx1_ischecked"

Populating a ListView from SharedPreferences

女生的网名这么多〃 提交于 2019-12-23 04:28:45
问题 What I'm looking to do is populate a ListView from an AlertDialog entry. I've tried to do this with SharedPreferences, previously I've had the last entry just saving into the ListView (if I entered more than one String), so when I left the activity and returned all that appeared in the list was my last entry. However I figured that problem out and have modified the save procedure to change the "Key" field of the stored preference by incrementing an attached Int variable. To give you the full

how to save intent data passed from 1st activity to 2nd activity

ⅰ亾dé卋堺 提交于 2019-12-23 04:28:20
问题 I have Myactivity which is getting the intent data from the former activity. The intent data is sent through a spinner of the activity. I want to save this intent data of the spinner to the Myactvity. the intent data should persist when i enter the Myactivity through menu option of next activity. 回答1: in your First Activity1 Intent myintent= new Intent(FirstActivity.this,SecondActivity.class); myintent.putExtra("Name", "your String"); startActivity(myintent); in Second Activity2 Intent