Hello friends we have already covered a couple of tutorials for android login example using php mysql.
But in the above mentioned tutorials, we were not maintaining the login session. Like once user has logged in to our app, user do not need to login again.
So in this android login example we will see how we can do Android User Session Management. And we will give a logout button from where user can logout from our app.
Android Login Example – Video
- You can check the following video to know exactly what we will be creating in this android log in tutorial.
- Now if you want to create this android login example, go ahead in this tutorial.
Creating Database and PHP Scripts
- For this tutorial I am using wamp server.
- This is my MySQL database.

mysql database
- As you can see I have a very small table with only three columns (id, email and password). You have to create the same.
- Now we will create two php script. The first one to connect to the database (dbConnect.php).
1 2 3 4 5 6 7 |
<?php define('HOST','localhost'); define('USER','root'); define('PASS',''); define('DB','androiddb'); $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect'); |
Quick Tip: Are you are thinking that closing php tag ‘ ?> ‘ is missing? Actually we do not need the closing tag for the files having only php code on it. You can still put the ?> closing tag but it will not make any difference.
- The next script to handle our login request. Create a new php file login.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php if($_SERVER['REQUEST_METHOD']=='POST'){ //Getting values $username = $_POST['email']; $password = $_POST['password']; //Creating sql query $sql = "SELECT * FROM users WHERE email='$username' AND password='$password'"; //importing dbConnect.php script require_once('dbConnect.php'); //executing query $result = mysqli_query($con,$sql); //fetching result $check = mysqli_fetch_array($result); //if we got some result if(isset($check)){ //displaying success echo "success"; }else{ //displaying failure echo "failure"; } mysqli_close($con); } |
Android Login Example
- Create a new Android Project.
- Add android volley library to your project dependencies.
1 2 3 4 5 6 7 |
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:design:23.0.0' compile 'com.mcxiaoke.volley:library-aar:1.0.0' } |
- Now create a new class named Config.java to store some important constants.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package net.simplifiedcoding.androidloginlogout; /** * Created by Belal on 11/14/2015. */ public class Config { //URL to our login.php file public static final String LOGIN_URL = "http://192.168.94.1/Android/LoginLogout/login.php"; //Keys for email and password as defined in our $_POST['key'] in login.php public static final String KEY_EMAIL = "email"; public static final String KEY_PASSWORD = "password"; //If server response is equal to this that means login is successful public static final String LOGIN_SUCCESS = "success"; //Keys for Sharedpreferences //This would be the name of our shared preferences public static final String SHARED_PREF_NAME = "myloginapp"; //This would be used to store the email of current logged in user public static final String EMAIL_SHARED_PREF = "email"; //We will use this to store the boolean in sharedpreference to track user is loggedin or not public static final String LOGGEDIN_SHARED_PREF = "loggedin"; } |
Desiging Android Login Activity
- First we will define colors. Inside values-> colors.xml write the following code.
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#085682</color> <color name="colorPrimaryDark">#033855</color> <color name="colorAccent">#FFFFFF</color> <color name="colorBackground">#147fbb</color> </resources> |
- In the layout file of your login activity write the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/colorBackground" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fitsSystemWindows="true"> <LinearLayout android:layout_gravity="center_vertical" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="56dp" android:paddingLeft="24dp" android:paddingRight="24dp"> <ImageView android:background="@drawable/logo" android:layout_gravity="center_horizontal" android:layout_width="150dp" android:layout_height="150dp" /> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="8dp"> <EditText android:id="@+id/editTextEmail" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" android:hint="Email" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="8dp"> <EditText android:id="@+id/editTextPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:hint="Password"/> </android.support.design.widget.TextInputLayout> <android.support.v7.widget.AppCompatButton android:id="@+id/buttonLogin" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:textColor="@color/colorAccent" android:layout_marginTop="24dp" android:layout_marginBottom="24dp" android:padding="12dp" android:text="Login"/> <TextView android:id="@+id/linkSignup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="24dp" android:text="No account yet? Create one" android:gravity="center" android:textSize="16dip"/> </LinearLayout> </ScrollView> |
- The above code will produce the following layout. We are not creating an Android Registration Form here. User will directly see the login page.

android login example
- Now come to the java code (In my case it is LoginActivity.java).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
package net.simplifiedcoding.androidloginlogout; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.AppCompatButton; import android.view.Menu; import android.view.View; import android.widget.EditText; import android.widget.Toast; import com.android.volley.AuthFailureError; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import java.util.HashMap; import java.util.Map; public class LoginActivity extends AppCompatActivity implements View.OnClickListener { //Defining views private EditText editTextEmail; private EditText editTextPassword; private AppCompatButton buttonLogin; //boolean variable to check user is logged in or not //initially it is false private boolean loggedIn = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); //Initializing views editTextEmail = (EditText) findViewById(R.id.editTextEmail); editTextPassword = (EditText) findViewById(R.id.editTextPassword); buttonLogin = (AppCompatButton) findViewById(R.id.buttonLogin); //Adding click listener buttonLogin.setOnClickListener(this); } @Override protected void onResume() { super.onResume(); //In onresume fetching value from sharedpreference SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME,Context.MODE_PRIVATE); //Fetching the boolean value form sharedpreferences loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF, false); //If we will get true if(loggedIn){ //We will start the Profile Activity Intent intent = new Intent(LoginActivity.this, ProfileActivity.class); startActivity(intent); } } private void login(){ //Getting values from edit texts final String email = editTextEmail.getText().toString().trim(); final String password = editTextPassword.getText().toString().trim(); //Creating a string request StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL, new Response.Listener<String>() { @Override public void onResponse(String response) { //If we are getting success from server if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){ //Creating a shared preference SharedPreferences sharedPreferences = LoginActivity.this.getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE); //Creating editor to store values to shared preferences SharedPreferences.Editor editor = sharedPreferences.edit(); //Adding values to editor editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, true); editor.putString(Config.EMAIL_SHARED_PREF, email); //Saving values to editor editor.commit(); //Starting profile activity Intent intent = new Intent(LoginActivity.this, ProfileActivity.class); startActivity(intent); }else{ //If the server response is not success //Displaying an error message on toast Toast.makeText(LoginActivity.this, "Invalid username or password", Toast.LENGTH_LONG).show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //You can handle error here if you want } }){ @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String,String> params = new HashMap<>(); //Adding parameters to request params.put(Config.KEY_EMAIL, email); params.put(Config.KEY_PASSWORD, password); //returning parameter return params; } }; //Adding the string request to the queue RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(stringRequest); } @Override public void onClick(View v) { //Calling the login function login(); } } |
- Now we need to code the next activity (Create a new activity for profile ProfileActivity.java).
- For this activity we need to create a menu for our logout button. So inside menu -> menu.xml write the following.
1 2 3 4 |
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menuLogout" android:title="Logout" /> </menu> |
- We need to create only a single TextView in our layout file for this activity (activity_profile.xml).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="net.simplifiedcoding.androidloginlogout.ProfileActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Large Text" android:id="@+id/textView" /> </LinearLayout> |
- Write the following code in ProfileActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
package net.simplifiedcoding.androidloginlogout; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class ProfileActivity extends AppCompatActivity { //Textview to show currently logged in user private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); //Initializing textview textView = (TextView) findViewById(R.id.textView); //Fetching email from shared preferences SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE); String email = sharedPreferences.getString(Config.EMAIL_SHARED_PREF,"Not Available"); //Showing the current logged in email to textview textView.setText("Current User: " + email); } //Logout function private void logout(){ //Creating an alert dialog to confirm logout AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setMessage("Are you sure you want to logout?"); alertDialogBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { //Getting out sharedpreferences SharedPreferences preferences = getSharedPreferences(Config.SHARED_PREF_NAME,Context.MODE_PRIVATE); //Getting editor SharedPreferences.Editor editor = preferences.edit(); //Puting the value false for loggedin editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, false); //Putting blank value to email editor.putString(Config.EMAIL_SHARED_PREF, ""); //Saving the sharedpreferences editor.commit(); //Starting login activity Intent intent = new Intent(ProfileActivity.this, LoginActivity.class); startActivity(intent); } }); alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); //Showing the alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { //Adding our menu to toolbar getMenuInflater().inflate(R.menu.menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menuLogout) { //calling logout method when the logout button is clicked logout(); } return super.onOptionsItemSelected(item); } } |
- Add Internet Permission to Your AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.simplifiedcoding.androidloginlogout" > <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".LoginActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ProfileActivity" > </activity> </application> </manifest> |
- Thats it, run your application now.

Android Login Example
- Bingo! its working fine.
- You can also download my source code from github. Visit the link given below.
[wp_ad_camp_1]
Common Error with this Android Login Example
- If you are using wamp or xampp server and getting blank toast message. Then this is often cause when your emulator cannot access your host. So you have to write the correct URL in Config.java file.
- To know what is your URL open your command prompt and type ipconfig.

ipconfig
- Here you will see your IP Address. 192.168.94.1 -> this is my root and I stored my php scripts inside Android/LoginLogout/
- So my URL is http://192.168.94.1/Android/LoginLogout/login.php
- To confirm it is correct open your emulator and write http://192.168.94.1/Android/LoginLogout (You have to write your address) in browser and check the browser can access it or not.

emulator
- If your browser can access your URL then it is fine.
- If you got more than one IP with ipconfig command. Try accessing all the IPs one by one in your browser to get the correct one.
Some More Android Application Development Tutorial To Check
- Android Retrofit Tutorial to Insert into MySQL Database
- Android Spinner Example to Load JSON using Volley
- Android Volley tutorial to Get JSON from Server
- Android Session Management using Shared Preferences
So thats all for this Android Login Example friends. Feel free to leave your comments if you are having any doubts or queries. Thank You 🙂
thanks bilal i am waiting for thistutorial for a long time
you spelled me wrong 😛 jokes apart
your welcOme and keep visiting
Hi, could you help me out with something? I want to send a notification (message) from my website (php) to an App (Android).
The website receives data from an Arduino, stores it in my database and once a particular message is seen (Alarm) a notification message has to be sent to the app. I’ve tried using a ‘Pushnotification’ but have been unsuccessful. I don’t know if I am using it wrong or have to use another means of notification.
The website is http://www.cars.site88.net
Please help… any suggestions or code will do as I have been at this for more than a month now.
Hi friend. Nice tutorial.
I have aquestion. Some time ago android volley library was not included in SDK android Studio. So I am not sure if we have to import library and then make the dependences or it is already included in SDK and we only need to include the dependences ?
Best Regards and thanks.
just include the dependencies and it will automatically download and add volley to ur project
additionally you can also download and import the .jar file of volley library
you can check the first volley tutorial i posted
Hi Belal
Thanks for the help. I just do it. Now I will try your exemple.
I come into your totorial just a few days ago, so some times it is difficult to find a tutorial since I can not see any index or inner searcher so when I have o find a tutorial I have to review all listed tutorials-
Is there any index where I can go directly?-
Congratulations again for all tutorials I have read in, relly very usefull for me, i am begginer and I am studing from home.
Regards
I cant download it. can you provide another link?
I emailed you the project at your email address you written on this comment
Hey a tutorial on user email verification would be great. Like after registering the user must verify their email by clicking a verification link sent to their email. Also, for this tutorial is there any way to just restrict a user to enter in just a certain email address? Like only @gmail.com is allowed?
Hi Belal Khan,
Wonderful tutorial that stand out from others.
However, the code doesn’t fully functional in my case. When I run the project on my android device, it keep stuck at the login page, the “Invalid username or password” pops up every time. I can’t successfully proceed to the ProfileActivity page. I am quite sure the server works fine and return “success” as I tested it on Postman. URL address is correct too, otherwise, “Invalid username or password” should not even pops up.
Can you please help me take a look at my project?
I can send it to you via email.
cheers!
Did you try downloading my project?
same issue with me..
download my project and check you are getting the error or not
bro, I’ve downloaded your project.
when I click on Login button, it shows “invalid username or password” message every time & also I receive a message in logcat: “KnoxVpnUidStorageknoxVpnSupported API value returned is false”.
Please help!!
Replace
LoginActivity.java line number 79 with this..
if(response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
actually there may be an extra space of success coming from server so trimming the space of response string should work.. try this
trim is necessary in my case too, because the server returns “success\n” and make sure that you save your file without BOM.
check for the conditions the issue is within it , had same problem , now solved
Can you make a retrofit version of authentication? I am really having a hard time making one.
Stay tuned and I will post a tutorial for this 🙂
Any updates on the retrofit version of this?
Thanks
Hi Belal,
Thank you for your tutorial . This is very useful for my final task .
Btw, how to make it be a multi-level user? In case , if a user with the level of ” admin ” will open the admin layout . As for the level of “user ” will open a user layout .
One more thing , how to make it display ” Current User = ( name ) ” where “name” is the field in mysql table.
Thanks once again
Store username in your database as well and then fetch the username to display.
and for admin and user you have to create separate database.
For the multi level user, i think if i create separate database, its very complex. So what if I make it easy with the dissection “if response = success then intent to admin.class, else if response = success2 then intent to user.class, else then ‘error login’ ”
Can you help me on php and java class coding? Thanks
Hi, could you help me out with something? I want to send a notification (message) from my website (php) to an App (Android).
The website receives data from an Arduino, stores it in my database and once a particular message is seen (Alarm) a notification message has to be sent to the app. I’ve tried using a ‘Pushnotification’ but have been unsuccessful. I don’t know if I am using it wrong or have to use another means of notification.
The website is http://www.cars.site88.net
Please help… any suggestions or code will do as I have been at this for more than a month now.
Great tutorial works a treat A+ keep up the good work.
Thanks a lot Belal. I have learnt a lot from your tutorials.
Keep them coming.
Can u make a retrofit version and using hostinger ? Cause last tutorial u are teaching tht
In this project you use wamp, if I use hostinger how I get the URL for login.php ? Is it same ??
i have learn a lot from your tutorial
how to implement log out ?
Check this tutorial
http://www.simplifiedcoding.net/android-login-example-using-php-mysql-and-volley/
hi I got the following error with layout. can help me? thanks. I have add design library support already
Rendering Problems The following classes could not be instantiated:
– android.support.design.widget.TextInputLayout (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:34) at android.support.design.widget.TextInputLayout.(TextInputLayout.java:103) at android.support.design.widget.TextInputLayout.(TextInputLayout.java:96) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:394) Copy stack to clipboard Failed to find the style corresponding to the id 2147418373 (8 similar errors not shown)
Hey ProBelal i am getting success when i run the php file via postman but when i run my app i am getting “Invalid username and password” error. So plz help me. I have implemeted downloaded as well as the code u hav given on this page.
Hi, Thanks for the tutorial, it looks really good, however i’ve copied your code exactly into android studio through the download and i’ve got my own login.php and connect.php files which work on a postman and i’ve added an email and password into myphpadmin, however when i enter these details into the user login form it doesnt work, i do not get invalid username or password and it doesnt take me anywhere? Please respond via the email I have provided,
Thanks,
Ryan
Hey Belal khan, nice post. i run your example and i have the same problem, the problem is that sometimes reponse in empty and sometimes returnes success, i check it with using system.out.println(response); before the if(response.equals). So i think the problem is that when you check the if statement is empty=success=false and always have the toast invalid name … Could you tell me what is wrong?
Hi belal
nice tutorail but I am getting an issue
when i type an email and password it always shows the toast invalid email and password.
why am i getting this issue.
Have you tried downloading my project?
On line number 79 of LoginActivity.java
if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){
change it to
if(response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
and try if it is working
invalid username or password! Solutions??
You are doing something wrong for sure.. recheck all the things it should work
On line number 79 of LoginActivity.java
if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){
change it to
if(response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
and try (y)
Download Link?
It is on the post.. You didnt see?
But it is locked.. to unlock it use any of the given three buttons
I completed this tutorial and ran into the toast message “Invalid Username or Password”. I see that a few individuals also have received the same error. Since I had completed the earlier login tutorial and it worked, I figured there ws some difference in the code and I found a way to make it work. Hope it save someone some time, as the solution wasn’t so obvious.
In the LoginActivity, the onResponse code is:
/Creating a string request
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
new Response.Listener() {
@Override
public void onResponse(String response) {
//If we are getting success from server
if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){
//Creating a shared preference
I modified that to match the previous tutorial.
StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL,
new Response.Listener() {
@Override
public void onResponse(String response) {
if(response.trim().equals(“success”)){
openProfile();
I also added the openProfile() from the previous tutorial like this:
private void openProfile(){
Intent intent = new Intent(this, ActivityUserProfile.class);
intent.putExtra(KEY_USERNAME, username);
startActivity(intent);
I think the response from server was not functioning correctly. Maybe if has to do with the line
if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){
Once I changed it to if(response.trim().equals(“success”)){ I was able to login in.
I’ve changed this according to your code but the toast message is still same “Invalid Username or Password”
Hi,
Thanks for this and the tutorial on user registration. User registration is working fine but this tutorial is not working. Nothing happens on button click. I am continuing this in the user registration project itself by making two java classes “userloginactivity” and “ProfileActivity”. I followed everything but unable to run it. Please help.
Regards,
Navin
May be you are getting an exception .. did you check the logcat?
same error, Invalid username or password. Pls… tells us correct code of this app
super tutorial Thank you .
Unfortunately, I have a little problem .
I do not use a local server as WAMP or co.
I would like to apply this tutorial on a online server service .
Unfortunately, I understand only half as I am still very new to the area .
how does the answer and query the php document ?
I try it on 000webhost.com
but unfortunately without success .
Maybe I can have someone help or has a tip for me .
Thank you.
and sorry for my bad english
Dont use 000webhost use hostinger.. check this post to get a free hostinger account
https://www.simplifiedcoding.net/android-custom-gridview-images/
Hello Belal, Do you have a tutorial on creating a feed view from MySql using volley but with a sliding menu? I am trying to add a sliding menu to my app in android studio but can’t figure out how to properly code the login and feed into the fragments. I’ve searched all over the internet trying to get help on this. Any help you can give will be much appreciated. Thank you!
cant make it work sir, it keeps on saying invalid ursername or password. i already downloaded your files and copied it but its just the same. i think something’s wrong in this part:
//Creating a string request
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL, new Response.Listener() {
@Override
public void onResponse(String response) {
//If we are getting success from server
if(response.trim().equals(Config.LOGIN_SUCCESS)){
//Creating a shared preference
sharedpreferences = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
//Creating editor to store values to shared preferences
SharedPreferences.Editor editor = sharedpreferences.edit();
//Adding values to editor
editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, true);
editor.putString(Config.EMAIL_SHARED_PREF, email);
//Saving values to editor
editor.commit();
//Starting profile activity
Intent intent = new Intent(MainActivity.this, MenuHome.class);
startActivity(intent);
}else{
//If the server response is not success
//Displaying an error message on toast
Toast.makeText(MainActivity.this, “Invalid username or password”, Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//You can handle error here if you want
}
}){
@Override
protected Map getParams() throws AuthFailureError {
Map params = new HashMap();
//Adding parameters to request
params.put(Config.KEY_EMAIL, email);
params.put(Config.KEY_PASSWORD, password);
//returning parameter
return params;
}
};
please help sir! 🙁
hey,.. did you solve the problem?Even I am facing the same,..please tell me if you have solved,…plzzzz,….
Hello belal, thanks for your tutorial but i want to keep the Mail on the EditTExt Email I dont know how to get the value of mail and auto-complet the Edit text.
thanks for your answer.
In my case app is running well but when i am clicking n login button then it is not functioning properly.I remains in same activity and also create one account button also not working properly,it is also not giving any response??????
Hi,
Nice tutorial however I am having some issues. I’m getting a ClassCastException that looks like the following:
E/Volley: [38488] NetworkDispatcher.run: Unhandled exception java.lang.ClassCastException: libcore.net.url.FileURLConnection cannot be cast to java.net.HttpURLConnection
java.lang.ClassCastException: libcore.net.url.FileURLConnection cannot be cast to java.net.HttpURLConnection
at com.android.volley.toolbox.HurlStack.createConnection(HurlStack.java:152)
at com.android.volley.toolbox.HurlStack.openConnection(HurlStack.java:162)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:102)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
Some help would be appreciated.
Thank you.
I figured out that this was to do with where I had my login.php file – however now I’ve uploaded it to a stable server, I get this error when trying to login on the app:
BasicNetwork.performRequest: Unexpected response code 500 for
Can you please help?
thanks
I got it to work after trying to change many things, I tried all these things in one go so do as I did and it should work:
1) On your MySQL database (PhpMyAdmin lets you do this with ease) create a new user (not root), give it all privileges and let the host be set to “Any Host”
2) Change dbConnect.php to suit your credentials – make sure you have the php files in the same server the MySQL database is on, that way you can use ‘localhost’ as the hostname. Make sure username and pass match the new one you just entered (I also added ?> at the end of dbConnect.php, not sure if this made any difference)
3) In ‘login.php’ at a semi colon at the end of the SQL statement (as well as the one after the php line) so it looks like this:
$sql = “SELECT * FROM users WHERE email=’$username’ AND password=’$password’;”;
This worked for me.
I advise that, once you get this working, you should change this statement into a PHP prepared statement, so this sort of query is vulnerable to SQL injection attacks.
Hope you all have as much luck with this as I did today!
Thanks
thank you so much for the tutorial.But i am unable to login,its showing invalid username or password.I am using 000webhost.com for the database.Please reply me soon,.. I have to submit it as a project in my college by monday.
Plzzzzzz,.. help meee,…… 🙂
login.php is not properly sending a response message. dbConnect is working as intended however something is happening that is causing neither success or failure to be sent. I have confirmed this by hard coding $username and $password. Any response by author is appreciated.
hey belal
I use your codr and this error is happend to me
02-10 22:13:02.281 4999-7118/com.example.nouf.gp I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
what is thats mean? any help people?
can you give me your username and password for your domain on hostinger because i am unable to run the project
I Kept looking for an application like this for 2 weeks ! untill i found you !
thank you so much ! everything is working perfectly .
im making an app for my final year project ! thanks a million ! .
I use the exact code as above—works on emulator but causes error on real device–plz help—
Errors are
Volley.noConnectionErro
Device has internet which I checked for sure
Your API is deployed in a real server or you are using xampp for real device as well. Xampp will not work for real device unless your device is connected with your computer using hotspot.
Can you show us , how to Post Data into Database , after a successful Login ?
Thanks buddy keep visiting. you can use Volley’s StringRequest to post data on mysql database..
hello, i want to insert name, age ,address and image in android will you help me?
When i have login and go to profile page, why it cannot exit the app when i try to touch the back button hardware ? It always go to ProfileActivity when i try to touch the back button hardware. Please give me the solution to get exit from the app when i touch the back button hardware. Thanks in advance.
people I need help pleeease
I still work in the login page for a week
I try many tutorials and the same error happed with me
when I click on login button nothing happened
pleeease who can help me :(((((
I work in localhost xampp
and every thing is the same on the belal tutorial
I also try his application and the same error (when I click login nothing )
Just confirm that your localhost is accessible by your emulator..
try opening the localhost in your emulator’s browser.
and check it opens or not
First of all, Belal Khan thank you for your time and for your tutorial this help me a lot and after a little bit of coding and with the same issues like other people here regarding Invalid Login i have found a solution is like utf8 or non ASCII characters…….
Just do the following:
SEARCH LINE 82* on LoginActivity.java
public void onResponse(String response) {
//If we are getting success from server
if(response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
AND CHANGE FOR THIS:
public void onResponse(String response) {
//If we are getting success from server
String final_response= response.replaceAll(“[^\\x00-\\x7F]”, “”); // will clean non ASCII characters
if(final_response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
Hy belal. Pleasehelp. My problem. Aide android app. Your code download and lib download okay. I run aide the your code, and 3 error.
Creating a string request
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
new Response.Listener() {
@Override
public void onResponse(String response) {
//If we are getting success from server
if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){
//Creating a shared preference
SharedPreferences sharedPreferences = LoginActivity.this.getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
//Creating editor to store values to shared preferences
SharedPreferences.Editor editor = sharedPreferences.edit();
//Adding values to editor
editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, true);
editor.putString(Config.EMAIL_SHARED_PREF, email);
//Saving values to editor
editor.commit();
//Starting profile activity
Intent intent = new Intent(LoginActivity.this, ProfileActivity.class);
startActivity(intent);
}else{
//If the server response is not success
//Displaying an error message on toast
Toast.makeText(LoginActivity.this, “Invalid username or password”, Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//You can handle error here if you want
}
}){
please help
Hi, I don’t know how you got yours working, but I found out there is a problem with the “String response” causing to flag the “Invalid username and password.”
“StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
new Response.Listener() {
@Override
public void onResponse(String response) {
//If we are getting success from server
if(response.equalsIgnoreCase(Config.LOGIN_SUCCESS)){”
I use system.out to debug the string, and I found that length of the string is different compare to the Config.Login_SUCCESS.
Config.Login_SUCCESS.length() displays 7 while String response.length() displays 8. This is why (response.equalsIgnoreCase(Config.LOGIN_SUCCESS) returns false. I checked the volleyLogin.php and echo “SUCCESS” is the same length as Config.LOGIN_SUCCESS.
I don’t know what caused the string length to increase from 7 to 8. I think there’s a problem with the dbConnect.php, because when you output a string “echo ‘sdfslkdjf'”, I found out the string response in changed.
Can you please check the php files? I also download the project, but same problem. Thanks.
May be the server is returning the string with an additional space.. in that case to be more sure use json as the response..
You can also try by trimming the response using the trim() method.
Same here… Spending 3 hours and I found what caused it. There was an extra character in “dbConnect.php”. I fixed it and working properly. I hope your problem will be solved.
may i know what is the extra character in “dbConnect,php”? I have the problem to login in, always got invalid username and password, i don’t know how to solve it, please share with me, thanks
Hello , Belal Khan ! Thank you for all your tutorials. Im working on my project which founded on your examples and all working great, but can you please tell or make a tutorial how to make login for user (user_activity) and login for admin (admin_activity) separately ? I tried to make verification by E-mail (if editTextLogin.getText().toString()=”[email protected]” for example then go to admin_ativity else go to user_activity) . Thats not a real code, thats just for example, but real code doesnt work. Help me, please
Hello sir,
I am having some problems with my app. Android monitor delivers this messages to me when i click on my login button.
E/Volley: [205196] BasicNetwork.performRequest: Unexpected response code 400 for http:/link.php
And the Toast message says Invalid username or password.
Do you maybe know how I can fix it?
Really thank you very much Belal =)
your tutorial help me alot in understanding how to code the login page in my project. I do some changes because I used android studio with phpmyadmin on Hostinger, and its work correctly =)
– But in my project I have 3 different user (admin, manager, customer) who should each access three different interfaces, how could I do it, do you have any idea?
– can you make tutorial for that I am sure it will help others as well …
Thank you again, you are the best <3
the login is work fine.
but i have database contain 3 three table (admin,employee,student).
when i press login button i want the app check who is login if he is the teacher take him to teacher activity page , if student take him to student activity page…
any idea how to implement it??
Like many here I was having trouble with the login failing even for correct inputs. After spending 4-5 hours on this one problem, the solution turned out to be a small little command: ‘exit();’
The cause of the problem: data analytics returned as part of query results by sites such as 000webhost.
So, the actual output turned out to be:
success
To avoid having the last few lines of the analytics code, just add exit(); at the end of the php file, such as:
//if we got some result
if(isset($check)){
echo “success”;
}else{
echo “fail”;
}
mysqli_close($con);
exit();
}
And now this works! 🙂
small edit above (got cut out):
So, the actual output turned out to be:
success
…Hosting24 Analytics Code…
….script type=”text/javascript” src=”http://stats.hosting24.com/count.php”>
…End Of Analytics Code ……
Thank you very much, I am using 000webhost and your solution works!
please you can send login using PHP on my mail because i can’t download it please help me
i got this.. and worked
just add
its work. sorry for bad english. thanks for belal or balveeer hahaha ty
() without (
Hello
Thanx for tutorial it worked but can u send me the code for creating session management for login an logout
Plzz just help me out…
Thanx.
You can download the code from the link given below..
hi belal thank you alot…..
when i click on the login button there is no action at all
i think the problem is in this part
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
new Response.Listener() {
@Override
public void onResponse(String response) {
//If we are getting success from server
if(response.trim().equals(“success”)){
openProfile();
}else{
//If the server response is not success
//Displaying an error message on toast
Toast.makeText(MainActivity.this, “Invalid id or password”, Toast.LENGTH_LONG).show();
}
}
},
also ,,,,
i add a toast message her
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//You can handle error here if you want
Toast.makeText(MainActivity.this, “Problem in Button “, Toast.LENGTH_LONG).show();
}
and when i click the button this message apeare (Problem in Button )
have any idea about this problem
thnx ..
hey buddy your website really help me..
Hi Belal,
M getting this error could you please help very urgetn
Unexpected response code 404 for http://192.X.X.X/Android/LoginLogout/login.php
404 code means that you cannot connect with your server. okay now there is several option.
1. if you did not change anything to Bellal’s code maybe you should change the IP or change the location of PHP file in the htdoc(if you are using xampp) makesure the location of PHP file is inside htdoc/Android/LoginLogout/login.php
Hi Belal,
I wanna use my online db from hostinger mysql. I changed connectdb and login.php for my own tables, and connect to my db. but it didnt worked for me, what else i can do ?
Hi Belal, thanks for tutorial. One question, I have a table with fields, id, email, password, names. What I do is that in the ProfileActivity display the name of the user who is logged. Thanks!!
compile ‘com.mcxiaoke.volley:library-aar:1.0.0’ IS DEPRECATED!
You should edit this amazing tutorial, with this dependecy all work fine:
compile ‘com.android.volley:volley:1.0.0’
Thanks.
Yeah you are right.. but the method is still the same
this app work successfully
but I found bug on ProfileActivity cannot back ~> finish(); . I must press home button to close this app..
whats going wrong?
sir i am trying to connect to remote database .when put correct username and password to login ,it is always giving me error -incorrect username & password.
sir please help me
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.LOGIN_URL,
My code stops working from here
I gave toasts before this line and after this line
Same here, the code stops working at this line.
Anyone solved the issue?
same here, its not working after the above code,
please help i want to know what is going wrong in my code ,
You made my day..!!! Thanks Alot bro… I had to use this in my Final year project thanks thanks thanks… Keep sharing knowledge… 🙂
thanks bro … you are freakin genius keep up sharing your knowledge …
Hi belal,after I click button login , but nothing response, whats wrong???
you try toast from onErrorResponse() see if you actually stuck there.
if you get invalid email and password that means you have connection problem.
I have applied the code given by you but nothing happens when I click the login button.I have used the correct ip address as well. please help.
Hi belal
Just I try your example it’s very good
I have some problem
When l login success I need show user id also
Please help me
Now what if i want to make something in which user first needs to create its account and then rest ?
creating an acoount and accessing it after
hi, great tutorial; but after created two script php (login.php and dbConnect.php) where i must put these two scripts php?
Thanks
i have this error:”W/NetworkManagementSocketTagger: untagSocket(46) failed with errno -2″…why?
When i try to login i have this error:”invalid username or password”…. data are correct!
why i have this error?
THANKS
Hello sir,
When i am using this project on Wamp server it is working ok.
But when transfered this project on hostinger always get invalid username password error
Checked SQLconnection php script but no issue found.
Thank you very much. Your tutorial was very useful. I had the “Invalid username or password” problem due to I am using 000webhos, however I could fix it by adding exit() in the login.php.
Greetings from Mexico!
Hi Belal,
I still have invalid username/password problem. And i changed the 79-LINE to if(response.trim().equalsIgnoreCase(Config.LOGIN_SUCCESS)){
Btw thanks for tutorial
Salam! Thank you for making this tutorial…i download the code and import in to android studio and after run the the app without any error, but i run the app nothing will happen what was the problem?? i doesn’t change anything even url.
Hello sir,
Login is working fine…
can you let me know, how to display process dialog during login & where should i place this code into loginActivity.java?
help me!
Thanks
Hello. How to make this this tutorial of yours to not accept same email?
Hi! Belal,
I followed your tutorial exactly, but the problem is when i key in the username and password, the app always said “Invalid username and password”, i don’t know what happen, The emulator can link with my php, mean that, my connection no problem, buy why still can’t login ??
Hello, nice tutorials. Thank you. My database is itself hosted by a third party and have given me the hostname,username and password for manipulating the db. Since the entry point to DB is itself secured, how can I send the requests via volley?
Hi belal
Just I try your example it’s successfully running but
I had some problem
When l login success, It will only show the current user name but i didn’t saw the logout option in that page
Please help me
Hi Belal,
Tx lot for the tutorial. It’s really helpful. I want to modify jason request. In my case I am not passing User Name and Password as strings. Instead I want to pass a JSON string.
String jsonString= “{\n” +
” \”user_auth\”: {\n” +
” \”provider\”: \”direct\”,\n” +
” \”user\”: {\n” +
” \”email\”: \”[email protected]\”,\n” +
” \”password\”: \”mypassword\”\n” +
” }\n” +
” }\n” +
“} “;
So what modification do I have to make to this script since in your example you are directly passing user name and password retrieved from text box. Appreciate your help on this one.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.yashika.login, PID: 26799
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yashika.login/com.example.yashika.login.LoginActivityy}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.widget.TextInputLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2439)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1360)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.design.widget.TextInputLayout
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.yashika.login.LoginActivityy.onCreate(LoginActivityy.java:44)
at android.app.Activity.performCreate(Activity.java:6556)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1360)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.TextInputLayout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.yashika.login.LoginActivityy.onCreate(LoginActivityy.java:44)
at android.app.Activity.performCreate(Activity.java:6556)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1360)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.support.design.widget.TextInputLayout” on path: DexPathList[[zip file “/data/app/com.example.yashika.login-2/base.apk”],nativeLibraryDirectories=[/data/app/com.example.yashika.login-2/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:583)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.yashika.login.LoginActivityy.onCreate(LoginActivityy.java:44)
at android.app.Activity.performCreate(Activity.java:6556)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.access$900(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1360)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: Didn’t find class “android.support.design.widget.TextInputLayout” on path: DexPathList[[dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-volley_c29e2c439243134cc7c4de46f793be7a39277f65-classes.dex”, dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-support-annotations-23.4.0_f9ec1cace9a6ca1410b48dac94f556dfe9154cb5-classes.dex”, dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-slice_9-classes.dex”, dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-slice_8-classes.dex”, dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-slice_7-classes.dex”, dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-slice_6-classes.dex”, dex file “/data/data/com.example.yashika.login/files/instant-run/dex/slice-slice_5-c
Application terminated.
i am getting error.please help me.
hey would you solved these code error……………..
if yes pls reply me………!!!
I too have download this demo for login and also got the invalid username or password error.
I was going to debug but came up with a different and quicker solution :
first I added this to the error message toast for the invalid username : , response.trim()+”Invalid username or password”
so it looks like this :
Toast.makeText(LoginActivity.this, response.trim()+”Invalid username or password”, Toast.LENGTH_LONG).show();
This gives me an output directly to the screen to see the response. (I thought it could be a different response at different times)
This showed me an error in line 18 on the login.php script so I opened it and saw that the name of the table that the script was looking for was different to the name I gave the table in the sql (it doesn’t say in the tutorial what name it should be.)
after changing the name of the table (either in the login.php script or on the sql server) it worked perfectly.
Then I remembered that I had implemented the trim change suggested – so I tested it without the trim and it also worked fine.
hope this helps.
That’s very good observation and simple solution to many on this web site. The problem of “invalid username or password’ lies in the php code. If you replace Toast.makeText(LoginActivity.this,…… statement with the following :
Toast.makeText(LoginActivity.this, response.trim()+”Invalid username or password”, Toast.LENGTH_LONG).show();
you will be displayed with the error on your php code that needs correction.
My salute goes to shayke,
Thanks Aliyu Chika – much appreciated
Thank you shayke !
This really works like a charm. I’ve been figuring what the problem with the code all night long, reading all comments, and your comment really helps me so much ! From your 1 line of code I can figure out what is my problem with my .php file
very best tutorial 🙂
please I cant download the project
Please Send me the project code
Hi, I’m a beginner in android development. Help me. I’m stuck in this error in ProfileActivity.java 🙁
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Adding our menu to toolbar
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
helllo thenks for your awesome tutorial. But i have a little problem. I have success for login but if i’m not log out the app, i cannot back to my home, when i click back button its always bring me on my profile activity. can anybody give me a solution? thanks before
Thanks for the great tutorial . But I’m facing one problem. After successfully login it can’t go out from the app.
I try this code for go out
@Override
public void onBackPressed() {
//Execute your code here
finish();
}
But don’t working..
Please Sir help me……………………
i am having following error in logcat.
com.android.volley.serverError
Unexpected response code 405
I copied your code, and I keep getting “Invalid username and password” response
Please, give me a hint what I did wrong ?
Whats your db name and table name ? Check the php files to see if they are the same as the sql server. That was my problem.
I did it, but the Toast keep showing same problem
add this to the error message toast for the invalid username :
, response.trim()+”Invalid username or password”
so it looks like this :
Toast.makeText(LoginActivity.this, response.trim()+”Invalid username or password”, Toast.LENGTH_LONG).show();
what is your error now ?
Thanks for the great tutorial . But I’m facing one problem. After successfully login it can’t go out from the app.
I try this code for go out
@Override
public void onBackPressed() {
//Execute your code here
finish();
}
But don’t working..
Please Sir help me
Can you help me with user image on regiatration.
Thanks
Rishabh
I used this tutorial it worked fine. But today its showing this error. I went through all resources but i cannot find a solution.
error: E/Volley: [77579] BasicNetwork.performRequest: Unexpected response code 403
This is an error code from your web server : The 403 Forbidden error is an HTTP status code which means that accessing the page or resource you were trying to reach is absolutely forbidden for some reason.
Bro thanks a lot… I was searching for this and finally i found what i was looking for… keep helping us.. keep going..
Thanks You..
app is running but login button is not functioning …no changes on clicking it ..plz help us with required changes in the code …
Hi
You probably forgot to add:
in androidmanifest.xml
Site cut code.
android.permission.INTERNET
Thanks for the tutorial..i got a question.. How do u display Username instead of email. Like in Logging in you enter email and password then when you get to main screen it will display the user name.
Hi
Great toutorial. Everything works.
But i have question about menu.
If logout is only one position in menu it works like it should, but when i add one more position it doesnt. There is no reaction on click, other 2 options works.
Code:
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId())
{
case R.id.menuLogout:
if (id == R.id.menuLogout)
{
logout();
}
break;
case R.id.menulist:
Intent intent_menu_list = new Intent(this, ListActivity.class);
this.startActivity(intent_menu_list);
break;
case R.id.menuspot:
Intent intent_menu_add = new Intent(this, AddActivity.class);
this.startActivity(intent_menu_addspot);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Any sugestions ?
I found it. in case R.id.menuLogout, remove “if”
Maybe some one will need:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuLogout:
logout();
return true;
case R.id.menuPrefixlist:
Intent intent_menu_prefixlist = new Intent(this, PrefixListActivity.class);
this.startActivity(intent_menu_prefixlist);
return true;
case R.id.menuAddspot:
Intent intent_menu_addspot = new Intent(this, AddSpotActivity.class);
this.startActivity(intent_menu_addspot);
return true;
case R.id.menuHelp:
Intent intent_menu_help = new Intent(this, HelpActivity.class);
this.startActivity(intent_menu_help);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
After I’ve finished everything and then I run the app. The login button from my app seems unclickable. How do make this clickable.
HI
U must missed some part of tut.
As i think u didnt do java part just layout
thanks Belal you are the best , you help me many time with your codes i appreciate that .
Adel, from tunisia .
Hi Belal,
My PHP file is not returing success
Please help for the same
hey Belal with this with code myapplication get terminate…………
would you give any suggestion
please, send project to my email
I can’t Login ..i don’t know where to store my login.php …
igot this error “com.android.volley.ServerError” most of time when i use post method.
plz tell me why this error occur.
When I try to login I have this error: “Invalid username or password”…. data are correct!
I am using Xampp and my php script is returning me “success” message on correct login.
Plz help me ASAP.
Hi bro please help me how align a length text
If I align text by using xml
But when I run the app it can’t display
What I designed in xml
i got error message, unfortune application has stoped. what happen bellal?
How can I change the url with a specific port volley request?
Example:
public static final String LOGIN_URL = “http://myip:8888/Android/LoginLogout/login.php”;
please help me.
i think this file php missing “?>”
That is not necessary for the files having only php code
sory. hehe
need time to know when my false,
i forget permission internet ..
Hey ! Your website is really help me a lot.
Thankyou bro.
I dont have any error in it.
But I want to ask you one question.
I hope you can help me.
How can i display all my data from mysql to user interface.?
Yours is only for email. Could you please help me?
this is my loginprocess.php . I joined 3 tables on my database.
How can i retrieve the data according my php script?
Thankyou.