Guest User

Untitled

a guest
Aug 1st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. How to have persistent variable in android module?
  2. private static int counter = 0;
  3.  
  4. @Kroll.method
  5. public int increment() {
  6. setIncrementProp(1);
  7. return counter;
  8. }
  9.  
  10. @Kroll.setProperty
  11. public void setIncrementProp(int value) {
  12. counter = counter + value;
  13. }
  14.  
  15. var module = require("com.modulewhatever");
  16.  
  17. var testToast = Titanium.UI.createNotification({ message :module.increment().toString() });
  18.  
  19. var button = Titanium.UI.createButton({ title : "Test" });
  20.  
  21. button.addEventListener("click", function(e) { testToast.show(); });
  22.  
  23. SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
  24.  
  25. p.edit().putString("username", username).commit();
  26. p.edit().putString("password", password).commit(); //SECURITY HAZARD: read below...
  27.  
  28. String username = p.getString("username", "");
  29. String password = p.getString("password", "");
Add Comment
Please, Sign In to add comment