TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • Android
  • How to Create Multi User Login Apps in Android?
Android

How to Create Multi User Login Apps in Android?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
1 7,143
Share

if you are looking for the tutorial that shows how to create a multiple user login apps in Android and redirect to different activity based on user role, then you are in the right tutorial.

In the process of solving real world problem, you may need to develop such a system which may have multiple number of user of a single system and when each user login to the system they must need to access only the certain features of an application which means they don’t need to access all the feature. In general the administrator have access to all the features and normal user may not have. So, this tutorial is all about this.

If you don’t know how to create login form in anroid, first of all, you need to read these tutorials:

Login apps in Android: HERE

Login and Registration apps in Android  HERE

So, i consider that you have the basic knowledge of all these things, and required application in your system.

Steps:

 

1.Open Android Studio, go to file>new>new project; give application name click next, select phone and tablets;click next, select empty activity click next and finally click finish.

Now you project will open in android studio. Go to res>layout>activity_main.xml. Double click on activity_mail.xml file, select design section. And drag and drop two edittext and one button and change their properties as shown in the video. OR simply copy following code; keep in mind that you need to change the package name and application name.

Designing code:


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="55dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:text="Username"
android:textSize="25dp"
app:layout_constraintBottom_toTopOf="@+id/textView8"
app:layout_constraintEnd_toStartOf="@+id/txtUser"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_marginEnd="11dp"
android:layout_marginRight="11dp"
android:text="Password"
android:textSize="25dp"
app:layout_constraintBottom_toTopOf="@+id/textView9"
app:layout_constraintEnd_toStartOf="@+id/txtPass"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7" />

<TextView
android:id="@+id/textView9"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="285dp"
android:layout_marginEnd="36dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="36dp"
android:layout_marginStart="16dp"
android:text="User Type"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/spinner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8" />

<EditText
android:id="@+id/txtUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="34dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/txtPass"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView7"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="33dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView8"
app:layout_constraintTop_toBottomOf="@+id/txtUser" />

<Spinner
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="26dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toTopOf="@+id/btnLogin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toBottomOf="@+id/txtPass" />

<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="214dp"
android:layout_marginEnd="7dp"
android:layout_marginRight="7dp"
android:text="Login"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner" />
</android.support.constraint.ConstraintLayout>

2. Now goto java>yourpackagename.com.applicationname in my case java>com.techsupportnep.multiuser>MainActivity.java

a. Inside the class declare the following variable as:

EditText _txtUser, _txtPass;
Button _btnLogin;
Spinner _spinner;

b. Before writing below code you have to add two activity in your application. So for thsi:

Inside the onCreate method initialize each control as:


_txtPass=(EditText)findViewById(R.id.txtPass);
_txtUser=(EditText)findViewById(R.id.txtUser);
_btnLogin=(Button)findViewById(R.id.btnLogin);
_spinner=(Spinner)findViewById(R.id.spinner);
ArrayAdapter <CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.usertype, R.layout.support_simple_spinner_dropdown_item);
_spinner.setAdapter(adapter);
_btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String item = _spinner.getSelectedItem().toString();
if(_txtUser.getText().toString().equals("admin")&& _txtPass.getText().toString().equals("admin")&& item.equals("admin")){
Intent intent = new Intent(MainActivity.this, admin.class);
startActivity(intent);

}else if(_txtUser.getText().toString().equals("admin")&& _txtPass.getText().toString().equals("admin")&& item.equals("user")){
Intent intent = new Intent(MainActivity.this, user.class);
startActivity(intent);
}else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
}

}
});

Press shift+f10 or simply click in the play button below the menu of the android studio and then select your AVD either builtin AVD , or third party AVD or your phone device and then click proceed.

 

That’s it. If you have any confusion, you can watch the following video:

Continue Reading
Build an Android Multi-usercreate multi user login apps in androidcreate multi user login form in androidhow to create Login Activity When multiple users Access there own data?how to create multi user login appshow to create multi user login form in androidhow to create simple multi user login apps in androidMulti level login user and admin?multi user login android appsmulti user login apps in androidmulti user login form in androidmulti user login in androidprogramming tutRan Bahadur B.K.ranbahadurbkRanBKsimple multi user login apps in androidTechSupportNep
1 7,143
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to Generate and Send OTP SMS for Free Using java?

Next Post

How to Send an Email using C#.NET?

You might also like More from author
Android

How to Show Alert Dialog Box in Android?

Show Comments (1)
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.