Android App Development | Lecture#26 | Hive Learners

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
ยท@faisalaminยท
0.000 HBD
Android App Development | Lecture#26 | Hive Learners
<center><h2>๐“–๐“ป๐“ฎ๐“ฎ๐“ฝ๐“ฒ๐“ท๐“ฐ๐“ผ</h2></center>
<div class="text-justify">

Greeting dear members of Hive Learners, I hope you all are doing well. A warm welcome to you in the 26th chapter on Android App Development. In the previous lecture, we complete the Sign in and Sign-up coding and successfully tested the app. In today's Lecture, we will design the Welcome screen with some buttons and we will open this screen on successful; login. We also need to store another value in shared preference to save the session for later use. So let's get started.

![](https://images.ecency.com/DQmPSNsRvDcfduo6LQWPHoSiho4xQufriBF6QNhiY52u2Ke/multi_purpose_2_.png)


### [GitHub Link](https://github.com/faisalamin9696/HiveLearners2)

Use this GitHub project to clone into your directory. It will constantly get updated in the following lecture so you will never miss the latest code. Happy Coding!.

### What Should I Learn

- Design a welcome screen
- Store the session

### Assignment
- Design a welcome screen and store the login session

### Procedure

First of all, we need a new Empty Activity, ```Welcome_Activity```  and add some required widgets in the design layout of this welcome activity.

![](https://images.ecency.com/DQmdtrUHqgeQgSLdB4BB4YA6VeSXbmQvYiikBbWHMM7tYaB/image.png)

![](https://images.ecency.com/DQmYgSseDpXJrKGDg4c1gYfpy8CdbG2UnEnZ2piAb79stgB/image.png)

Hhave ere I two textview a Welcome text and a textview to show the username of a login user.

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Welcome_Activity"
    android:orientation="vertical"
    android:padding="8dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome"
        android:textSize="28sp"
        android:textStyle="bold"
        android:layout_gravity="center" />

    <TextView
        android:id="@+id/welcome_username_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="14sp"
        android:textStyle="bold"
        android:layout_gravity="center"
        android:layout_marginTop="4dp"/>
    

</LinearLayout>
```

![](https://images.ecency.com/DQmeZ8xvhUP4VYBTPFU7bRV37X275FrNC3oo7C9gc9eu1ak/image.png)


Now we add two card views wrapped in the 2 Liearlayouts. The first linear orientation is verticle and in it another linear layout with horizontal orientation. In this Linearlayuout e add two card views with weight=1 and in the card,,, view add the TextView. Here is the code.

```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:padding="8dp"
    tools:context=".Welcome_Activity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Welcome"
        android:textSize="28sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/welcome_username_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="4dp"
        android:text=""
        android:textSize="14sp"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2">

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_weight="1"
                app:cardBackgroundColor="@color/purple_200"
                app:cardCornerRadius="10dp"
                app:cardElevation="4dp"
                app:cardUseCompatPadding="true">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Deposit"
                    android:textColor="@color/white" />

            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_weight="1"
                app:cardBackgroundColor="@color/teal_700"
                app:cardCornerRadius="10dp"
                app:cardElevation="4dp"
                app:cardUseCompatPadding="true">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Transfer"
                    android:textColor="@color/white" />

            </androidx.cardview.widget.CardView>


        </LinearLayout>


    </LinearLayout>


</LinearLayout>
```

![](https://images.ecency.com/DQmbYBemDH3RcVzbLxuGazDYTHVxcThoEYZoSNZge1Z1KPv/image.png)

Now we are ready with the design declare and initialize the username in the ```WelcomeActivity.java``` file. Also, declare and initialize the sharedPreferences.

![](https://images.ecency.com/DQmQBaHgWCZ7PMt1fR55HMWU8g8WQyzfChBYstuCiDNZCWA/image.png)

Now we need to add a value in sharedPreference that will tell us which account is login currently. We also use a logic in ```Main_Activity.java``` that check is this value is empty or not. If not empty then it will redirect the user to welcome screen without login again.
```
sharedPreferences.edit().putString("login_account",email_et.getText().toString()).apply();
```

![](https://images.ecency.com/DQmXa8eGZHvM3fsSpEJXvyic16gC6Mbibxfb4ZuzfuXYAmA/image.png)

Here is the logic that we use in the Main_Activity.java on app start to check the session.

![](https://images.ecency.com/DQmWm8gRqRaGB9apTYBXDjvy3RHfgREjw6JY7CZCK8rPti1/image.png)


Now on welcome screen we need to set the user name in welcome_username_tv, we get it from the sharedPreferences. First we need to get the login user email by using login_account key from sharedPreferences then we use this email_name to get the username.

![](https://images.ecency.com/DQmSCeEWSXUtHpUMKTjGWDSiD6Mwfbu5J1RVfXJeajNHySX/image.png)

Let's run and check if the app is working or not.</div>

![](https://images.ecency.com/DQmZJt3DXu3memSwYMpPWfFtC3PzT3e6R6LTE3Q9u8ebjjQ/image.png)

<center>
![hl_divider.png](https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png)

<h2>Thank You</h2>

![hl_footer_banner.png](https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png)
<div class="pull-left"><a href="https://discord.gg/7Bzqv4qUMT">
<img src="https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"/></a>
</center>


๐Ÿ‘ , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,