Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rcc.www.loginpage;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity
- {
- EditText name, pass;
- SharedPreferences savedData;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- name = findViewById(R.id.username);
- pass = findViewById(R.id.password);
- savedData = getSharedPreferences("file", 0);
- String username = savedData.getString("name", "No user found.");
- if(!username.equals("No user found.")){
- Intent intent = new Intent(MainActivity.this, Main2Activity.class);
- startActivity(intent);
- }
- }
- public void login(View view){
- /* savedData = getSharedPreferences("file", 0);
- SharedPreferences.Editor pin = savedData.edit();
- pin.putString("name", name.getText().toString());
- pin.putInt("password", Integer.parseInt(pass.getText().toString()));
- pin.apply();
- Intent intent = new Intent(MainActivity.this, Main2Activity.class);
- //Bundle data = new Bundle();
- //data.putString("Name", name.getText().toString());
- //data.putInt("Password", Integer.parseInt(pass.getText().toString()));
- //intent.putExtras(data);
- startActivity(intent);*/
- Intent intent = new Intent(MainActivity.this, Main2Activity.class);
- String username = name.getText().toString();
- int password = Integer.parseInt(pass.getText().toString());
- SharedPreferences.Editor pen = savedData.edit();
- pen.putString("Name", username);
- pen.putInt("Password", password);
- pen.apply();
- startActivity(intent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement