Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. private TextView usernameHeader, passwordHeader;
  2. private EditText username, password;
  3. private Button loginButton;
  4. private Handler alertHandler;
  5. private String userRes, passwdRes;
  6. SharedPreferences sharedPreferences;
  7. public static final String MySession = "MySession";
  8. public static final String nameField = "nameKey";
  9. public static final String passwordField = "passwordKey";
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_login);
  15.  
  16. loginButton = (Button) findViewById(R.id.loginButton);
  17.  
  18. username = (EditText) findViewById(R.id.username);
  19. password = (EditText) findViewById(R.id.passwd);
  20.  
  21. loginButton.setOnClickListener(new View.OnClickListener() {
  22. @Override
  23. public void onClick(View v) {
  24.  
  25. sqlThread.start(); //The loginIntent is called inside the thread using a handler
  26. }
  27. });
  28.  
  29. }
  30.  
  31. public void loginIntent(){
  32.  
  33. try{
  34. sharedPreferences = getSharedPreferences(MySession, Context.MODE_PRIVATE);
  35.  
  36. SharedPreferences.Editor editor = sharedPreferences.edit();
  37.  
  38. editor.putString(nameField, userRes);
  39. editor.putString(passwordField, passwdRes);
  40. editor.apply();
  41. //editor.commit();
  42.  
  43. }catch (Exception ex){
  44. ex.printStackTrace();
  45. }
  46.  
  47. Intent intent = new Intent(LoginActivity.this, MainActivity.class);
  48. startActivity(intent);
  49.  
  50. }
  51.  
  52. SharedPreferences sharedPreferences;
  53. private String name;
  54.  
  55. @Override
  56. protected void onCreate(Bundle savedInstanceState) {
  57. super.onCreate(savedInstanceState);
  58. setContentView(R.layout.activity_main);
  59.  
  60. submitButton = (Button) findViewById(R.id.submitButton);
  61.  
  62. mMapView = (MapView) findViewById(mapView);
  63. map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 34.056295, -117.195800, 16);
  64. mMapView.setMap(map);
  65.  
  66. sharedPreferences = getSharedPreferences(LoginActivity.MySession, Context.MODE_PRIVATE);
  67.  
  68. name = (String) sharedPreferences.getString(LoginActivity.nameField,"");
  69.  
  70. Toast.makeText(MainActivity.this,name,Toast.LENGTH_LONG).show();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement