Advertisement
Guest User

sharedPreferences|Save&Update

a guest
Dec 7th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. //Eu conseguir enviar e receber dois valores diferentes em uma intent
  2. @Override
  3. public void onBackPressed() {
  4.  
  5. if(checkBox.isChecked())
  6. {
  7.  
  8. String trueThumb_check = "checked_thumb";
  9. Intent i = new Intent(getBaseContext(), MainActivity.class);
  10. i.putExtra("trueThumbnail", trueThumb_check);
  11. startActivity(i);
  12. killAc();
  13. }
  14. else
  15. {
  16. Intent i = new Intent(getBaseContext(), MainActivity.class);
  17. i.putExtra("trueThumbnail", "");
  18. startActivity(i);
  19. killAc();
  20. }
  21.  
  22. }
  23.  
  24. //Então recebi valores diferentes:
  25. try {
  26. Intent thumb_check = getIntent();
  27. String thumb_thumb = thumb_check.getStringExtra("trueThumbnail");
  28.  
  29. if (thumb_thumb.contains("checked_thumb")){
  30. Toast.makeText(MainActivity.this, "checkBox ativo", Toast.LENGTH_SHORT).show();
  31.  
  32. } else {
  33. Toast.makeText(MainActivity.this, "not checkBox", Toast.LENGTH_SHORT).show();
  34. }
  35.  
  36. } catch (Throwable e) {
  37. e.printStackTrace();
  38.  
  39. //Mas não estou conseguindo salvar o resultado. Ele precisa ser salvo e atualizado quando o checkBox for acionado
  40.  
  41. SharedPreferences sharedPref = getSharedPreferences("ch4an.ytheloader", MODE_PRIVATE);
  42. SharedPreferences.Editor editor = sharedPref.edit();
  43. editor.putString("trueThumbnail", thumb_thumb);
  44. editor.commit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement