<pre>package com.example.androidapp; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import com.google.android.material.textfield.TextInputEditText; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; public class Login extends AppCompatActivity { EditText username, password; Button btnLogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); username = findViewById(R.id.editTextEmail); password = findViewById(R.id.editTextPassword); btnLogin = findViewById(R.id.buttonLogin); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(TextUtils.isEmpty(username.getText().toString()) || TextUtils.isEmpty(password.getText().toString())){ Toast.makeText(Login.this,"Username / Password Required", Toast.LENGTH_LONG).show(); }else{ //proceed to login login(); } } }); } public void login(){ LoginRequest loginRequest = new LoginRequest(); loginRequest.setUsername(username.getText().toString()); loginRequest.setPassword(password.getText().toString()); Call<LoginResponse> loginResponseCall = ApiClient.getUserService().userLogin(loginRequest); loginResponseCall.enqueue(new Callback<LoginResponse>() { @Override public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) { Log.d("@sid","res"+response.code()); if(response.isSuccessful()){ Toast.makeText(Login.this,"Login Successful", Toast.LENGTH_LONG).show(); final LoginResponse loginResponse = response.body(); new Handler().postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(Login.this,Permission2.class).putExtra("data",loginResponse.getUsername())); } },700); }else{ Toast.makeText(Login.this,"Login Failed", Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<LoginResponse> call, Throwable t) { Toast.makeText(Login.this,"Throwable "+t.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } }); } }
loginResponse.getUsername()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)