CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

Android Studio – LoginActivity – Add Login Activity to Android Project

Android Studio – LoginActivity is a pre-defined Activity we can add to our Project in Android Studio. In this article, I am going to explain, add LoginActivity and launch it when we Run the Application.

Step 1. Open our Android Project “MyApp“, which we have created in our Previous Article “Android Studio : Create Android Project“.

Step 2. Lets’ add “Login Activity” to our Android Project “MyApp“. We already have a “Main Activity” which is displaying the “Hello, World!” message, when we Run the Project.

In addition to the “Main Activity“, we are going to add “Login Activity“.

Right-click on the Android view (where we are seeing the list of files); Android Studio will display the context menu. Select New menu item -> select Activity menu item -> and then select “Login Activity” menu item to start adding an Activity to the Project.

Android Studio - New LoginActivity
Android Studio – New LoginActivity

Step 3. Android Studio will open the “Configure Activity” dialog. Keep the same default values in:

Activity Name: LoginActivity

Layout Name: activity_login

Title: Sign in

Package name: com.codesteps.david.myapp

Source Language: Java

Android Studio - Configure LoginActivity
Android Studio – Configure LoginActivity

Click on the “Finish” button to add the “Login Activity” activity to the “MyApp” Project.

Step 4. You will see, “activity_login.xml” is added under res/layout. And LoginActivity class is added under java / com.codesteps.david.myapp.

Android Studio, automatically starts analyzing the code and it will display the report; once the Analysis is completed.

To me, it displayed a “13 warnings found” message; after the analysis was completed. We will look into these later.

Step 5. Lets’ Run the Project, and observe that; again you will see the “Hello, World!” message. But we have added “Login Activity” to display the login page. Why it is not showing.?

In order to show our Activity, when we Run the Project; we should set our Activity as a LAUNCHER. LAUNCHER Activities will first appear when we launch the Application.

Step 6. Open AndroidManifest.xml file which is under app/manifests. This manifest file contains activities, and the attributes, actions, categories, etc.

Observer that, MainActivity is with the LAUNCHER category. And the MAIN action is defined for it.

What we need to do now is; remove or comment on these elements from “MainActivity” and add them to our “LoginActivity“.

Once the changes are done, save the file “AndroidManifest.xml“. After the changes, it looks like below:

Step 7. Re-run the Project and observe that; now our “LoginActivity” is shown when we launch the Application.

Android Studio - LoginActivity Launched
Android Studio – LoginActivity Launched

I am closing this Article here. Will discuss more Android Programming in my upcoming Articles.

I hope you liked this article. Please post the feedback through the below Comments.

[..] David

Android Studio – LoginActivity – Add Login Activity to Android Project

3 thoughts on “Android Studio – LoginActivity – Add Login Activity to Android Project

  1. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I get in fact enjoyed account
    your blog posts. Any way I will be subscribing to your feeds
    and even I achievement you access consistently rapidly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top