Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre>package com.example.androidapp;


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 retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class Login extends AppCompatActivity  {

EditText  username, password;
Button btnLogin;

protected void onCreate(Bundle savedInstanceState) {

username    = findViewById(;
password = findViewById(;
btnLogin      = findViewById(;

btnLogin.setOnClickListener(new View.OnClickListener() {

    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();
            //proceed to login

public void login(){
    LoginRequest loginRequest = new LoginRequest();

    Call<LoginResponse> loginResponseCall = ApiClient.getUserService().userLogin(loginRequest);
    loginResponseCall.enqueue(new Callback<LoginResponse>() {

        public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {


                Toast.makeText(Login.this,"Login Successful", Toast.LENGTH_LONG).show();
                final LoginResponse loginResponse = response.body();

                new Handler().postDelayed(new Runnable() {

                    public void run() {

                        startActivity(new Intent(Login.this,Permission2.class).putExtra("data",loginResponse.getUsername()));
                Toast.makeText(Login.this,"Login Failed", Toast.LENGTH_LONG).show();

        public void onFailure(Call<LoginResponse> call, Throwable t) {
            Toast.makeText(Login.this,"Throwable "+t.getLocalizedMessage(), Toast.LENGTH_LONG).show();


What I have tried:

Whenever I am trying to make a login page for my application, its showing login failed and its not passing intent as well as unable to pass the data on 2nd page of my application. I am helpless and not getting any idea to resolve this issue. I request you to kindly check my above coding and let me know if I have done anything wrong.
David Crow 18-Jun-20 12:15pm    
Have you stepped through the code using the debugger? Is an exception being thrown? What is being returned from loginResponse.getUsername()?
Member 14866477 19-Jun-20 1:51am    
Sir, I am new into it and currently I am running the app on emulator, whenevr I am running the app, the login page is opening after that I am filling my credentials (email and password) and clicking on login button and the apps gets shut down automatically.

I am new to it and it is my first project. Can you please help me in this sir?
David Crow 19-Jun-20 8:42am    
"Can you please help me in this sir?"

See my previous reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900