Activity Preference (Design) In Android - Day Two

Introduction

In this article we will study how to design the user interface and implement some easy code, but it is mandatory you have some experience in creating Android Studio projects. Now we will discuss the following topics.

  • Starting Another
  • Activity Respond to the Button
  • Create the Second Activity
  • Web View
  • Saving Data
  • Saving Key-Value Sets
Before starting, I would like you to visit the previous article:

Step 1: Now open the Android studio and click on new project, then press next button, choose the API leve, and select Empty template with now activity; now left click on res folder and create a directory and give the name layout and then press Ok button

directory

Click ok

Step 2: Now left click on first directory and give the name Main Activity; now you see that layout session the content.xml file  appears to have deleted this file because it is not necessary for us.

new activity

Delete content

Step 3: Now when Home Activity is created press double click on class file and delete the following code because it is not essential for us.

class file

Step 4:
Now after deleting the code you create more activities, you have two options for creating an activity. The first one is the previous method and the second is that you click on class file and press Ctrl C and then Ctrl V and then change the activity name and  you simplt make the layout section also. The following picture is given below forthe hierarchy of activities and layouts.

layout section

Step 5: Now mention allthe activities' names in AndroidManaifest.xml file and also add internet reference permission for using the app in future. I will make clear to you how I added INTERNET reference in this file

AndroidManaifest.xml file

Step 6: Now in Home activity we add two buttons in layout and set the name. We have two options; first, we create a button with code and second, we drag and drop, but this is not a good practice. Now I am showing code as well as button.

Home activity

Step 7: Now we make a scenario that when user presses the BROWSER button any following URL is open so in this first we will work on BrowserActivity.java file and add this code in Java file and we will implement the layout file by taking the Web View.

layout

Now open BrowserAcivity.java file and paste these two lines in it and then run the application

BrowserAcivity

Step 8: Now move to the HomeActivity.java class and add this code in it and we use intent classes to open other activities like Bowser activity

activities

Step 9: Now click on the Browser button and you can see that Google is open; now you can search anything here but remember that you add INTERNET permission in AndroidManifest.xml file.

run

Read more articles on Android:

Up Next
    Ebook Download
    View all
    Learn
    View all