I have created a login page which users can just enter their username (No passowrd or auth needed) and it will be displayed on the next activity. But every time you open the app you have to enter your username. How do i make it remember the username. (Language-Java)
Thanks!
(I am a beginner)
package com.example.app;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button btn;
EditText et;
String st;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn= findViewById(R.id.button);
et=findViewById(R.id.edittext);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent(MainActivity.this, Welcome.class);
st=et.getText().toString();
i.putExtra("Value",st);
startActivity(i);
finish();
(This one is the activity where user enters their username)
package com.example.app;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Welcome extends AppCompatActivity {
TextView tv;
String st;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
tv=findViewById(R.id.textView);
st=getIntent().getExtras().getString("Value");
tv.setText(st);
}
}
(This is the welcome activity)