Guest User

Untitled

a guest
Jul 23rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class Test1
  2. {
  3. ...
  4. @JavascriptInterface
  5. public String method1()
  6. {
  7. String title = 1;
  8. return title;
  9. }
  10. }
  11. public class Test2
  12. {
  13. public void method2()
  14. {
  15. title //ошибка компиляции - переменная title не видна из этого блока кода
  16. }
  17. }
  18.  
  19. public class Test1
  20. {
  21. ...
  22. @JavascriptInterface
  23. public String method1()
  24. {
  25. String title = 1;
  26. SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  27. SharedPreferences.Editor editor = pref.edit();
  28. editor.putString("key_name", title); // сохранение переменной
  29. return title;
  30. }
  31. }
  32. public class Test2
  33. {
  34. public void method2()
  35. {
  36. SharedPreferences pref = mContext.getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  37. String title = pref.getString("key_name", null);
  38. }
  39. }
Add Comment
Please, Sign In to add comment