SlideShare a Scribd company logo
1 of 16
Create New Activity
ANDROID MOBILE APPLICATION
TRAINING VIDEO - 3
Copyright © 2020 Transpose Solutions. All Rights Reserved.
OVERVIEW
In this tutorial, we will learn how to create
new activity to an exisiting android project,
send user input from one activity to another
and add navigation button to the app bar for
the user to return to parent screen.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
OPEN AN EXISTING PROJECT
From your task bar/start menu, click open “Android
Studio”
In the Welcome to Android Studio window:
 Click Open an existing Android Studio project.
In the Open File or Project window:
 Go to Android Studio Projects Folder and Select My Mobile App – the project
we created in our earlier tutorial and click OK.
Note: If you have not viewed our earlier tutorial – create new layout, please
view that before starting this tutorial.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
OPEN MAIN ACTIVITY CLASS
Android Studio main window appears after some process. We
need to open MainActivity class (Jave file) – code behind the
main_activity.xml:
Click Open app > java > com.transposesolutions.mymobileapp >
MainActivity.
Add a Method “displayMessage”
Note: This training material uses Android Studio v3.6.1. Package name
“com.transposesolutions.mymobileapp” is our domain and app name, you
should have your own package name.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
ADDING A METHOD
We need to create the displayMessage() in the MainActivity class, this method will be used to
start a new activity when app user clicks the submit button.
Click open – app > java > com.transposesolutions.mymobileapp > MainActivity
Add the following displayMessage() method stub inside AppCompactActivity:
Note: You might see an error because Android Studio cannot resolve the View class used as the method argument. To clear the error, click the View declaration,
place your cursor on it, and then press Alt+Enter, or Option+Enter on a Mac, to perform a Quick Fix. If a menu appears, select Import class.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
DEFINE - CLICK EVENT HANDLER
Now, let us define the click event handler for the “Submit” button in the file
activity_main.xml by adding the android:onClick:
Open app > res > layout > activity_main.xml.
Select the button in the Layout Editor.
In the Attributes window, locate the onClick property
Select “displayMessage” from its drop-down list.
Now when the “Submit” button is tapped, the system calls the displayMessage() method.
Note: We need to add few lines of code to the displayMessage(), so that the system
can read the contents of the EditText (User input) and deliver that text to another
activity which we will create next by adding a new activity to display the user input
from main_activity_xml.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
ADD NEW ACTIVITY
Let us add new activity to the project to display the user input from
main_activity.xml.
Please follow the following steps to add a new activity:
In the Project window, right-click the app folder and select New > Activity >
Empty Activity.
In the Configure Activity window, enter "DisplayActivity" for Activity Name.
Leave all other properties set to their defaults and click Finish.
Now, main window appears after some processes with activity_display.xml opened
with the layout editor.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
OPEN – LAYOUT EDITOR
Let us open the layout editor, set the margin to the display_activity.xml:
If your editor shows the XML source, click the Design tab.
Click Select Design Surface and select Blueprint.
Click Show in the Layout Editor toolbar and make sure that Show All
Constraints is checked.
Make sure Autoconnect is off.
Click Default Margins in the toolbar and select your margin to “24”. If needed,
you can adjust the margins for each view later.
Click Device for Preview in the toolbar and select 5.5, 1440 × 2560, 560 dpi
(Pixel XL).
Copyright © 2020 Transpose Solutions. All Rights Reserved.
ADD WIDGETS
Let us add new UI string to app “app_message”, add the following widgets to the
display_activity.xml and apply styles:
TextView with ID: “welcome_message” – To display a welcome message and set the
following:
Set layout width: 0dp; layout margin top: 20dp
Set widget property to “Center - Horizontally”
Locate the text property, which is currently set to “Name” and delete the value. Then, click
“Pick a Resource” and select “app_message” from the list.
Set text gravity to “Center”; Set text size: 30 sp and text color: @color/colorAccent
TextView with ID: “user_input” – To display the text entered by the app user in the main
activity
Set layout width: 0dp; layout margin top: 20dp
Set widget property to “Center - Horizontally” and layout_constraint top to bottom
Set text gravity to “Center”; Set text size: 30 sp and text color: @color/colorPrimary
Copyright © 2020 Transpose Solutions. All Rights Reserved.
ADD NAVIGATION
Let us add a navigation button to app bar for the app user to return to
main_activity.xml, to do that we need to declare “main_activity.xml is the parent screen in
the AndroidManifest.xml:
 Open the file at app > manifests > AndroidManifest.xml
 locate the <activity> tag for DisplayMessageActivity replace <activity> tag with
below code:
Copyright © 2020 Transpose Solutions. All Rights Reserved.
Next, we need to go back to MainActivity class file to add few lines of code to the displayMessage(), so that the
system can read the contents of the field and deliver that text to display_activity.xml.
USING - INTENT OBJECT
Let us open MainActivity Class and add few lines of code to the displayMessage(), for this purpose,
we use “Intent” object to start display_activity.xml and “putExtra()” method to add the user
entered values from the “EditText” to Intent.
Fill in the following code to displaymessage(), add SEND_MESSAGE constant and import required
class:
Note: For more technical documents about “Intent” can be accessed from Google developer guide: https://developer.android.com/reference/android/content/Intent
Copyright © 2020 Transpose Solutions. All Rights Reserved.
DISPLAYMESSAGE()
Let us examine, what does the code we just added to the displayMessage():
The Intent constructor takes two parameters, a Context and a Class.
The Context parameter is used first because the Activity class is a subclass of Context.
The Class parameter of the app component, to which the system delivers the Intent,
is, in this case, the activity to start.
The putExtra() method adds the value of EditText to the intent. An Intent can carry
data types as key-value pairs called extras.
Your key is a public constant SEND_MESSAGE because the next activity uses the key
to retrieve the text value.
The startActivity() method starts an instance of the DisplayActivity that's specified
by the Intent.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
DISPLAY USER INPUT
To display the user input from main_activity.xml to display_activity.xml. For this purpose, we use
Intent object and “getIntent()” method.
Let us open DisplayActivity Class and fill in the following code to onCreate() Method and import
required class :
Now, we can run the app to view the changes we have done so far in this tutorial.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
RUN YOUR APP
Use Android studio emulator to run your app:
In the toolbar, select your app from the run/debug configurations drop-down
menu.
 From the target device drop-down menu, select the AVD that you want to run
your app on.
 Click Run
Android Studio installs the app on the AVD and starts the
emulator.
Copyright © 2020 Transpose Solutions. All Rights Reserved.
Conclusion
We hope you were able to follow the instruction mentioned this tutorial, please find the
final output of screen we developed so far:
Copyright © 2020 Transpose Solutions. All Rights Reserved.
Main_Activity.xml Display_Activity.xml
Thank you for watching the video!
We hope the training video 1, 2 and 3
was helpful. Please read the
description of this video and external
weblink provided to learn more…
Copyright © 2020 Transpose Solutions. All Rights Reserved.

More Related Content

What's hot

Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAhsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul Karim
 
Rc085 010d-vaadin7
Rc085 010d-vaadin7Rc085 010d-vaadin7
Rc085 010d-vaadin7Cosmina Ivan
 
Create yourfirstandroidapppdf
Create yourfirstandroidapppdfCreate yourfirstandroidapppdf
Create yourfirstandroidapppdfmurad3003
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User InterfaceMarko Gargenta
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAhsanul Karim
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Ios actions and outlets
Ios actions and outletsIos actions and outlets
Ios actions and outletsveeracynixit
 
Write an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxWrite an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxvishal choudhary
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callmaamir farooq
 
Android Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptxAndroid Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptxvishal choudhary
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layoutKrazy Koder
 

What's hot (19)

Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
 
Rc085 010d-vaadin7
Rc085 010d-vaadin7Rc085 010d-vaadin7
Rc085 010d-vaadin7
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
 
Create yourfirstandroidapppdf
Create yourfirstandroidapppdfCreate yourfirstandroidapppdf
Create yourfirstandroidapppdf
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User Interface
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
 
List Views
List ViewsList Views
List Views
 
android layouts
android layoutsandroid layouts
android layouts
 
Ios actions and outlets
Ios actions and outletsIos actions and outlets
Ios actions and outlets
 
Write an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptxWrite an application that draws basic graphical primitives.pptx
Write an application that draws basic graphical primitives.pptx
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Exercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone callExercises broadcast receiver,incoming phone call
Exercises broadcast receiver,incoming phone call
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Android Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptxAndroid Application that makes use of RSS Feed.pptx
Android Application that makes use of RSS Feed.pptx
 
Presentation
PresentationPresentation
Presentation
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
 
Android development part 2
Android development part 2Android development part 2
Android development part 2
 

Similar to Create New Android Activity

Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidDenis Minja
 
Tang doanh thu quang cao di dong
Tang doanh thu quang cao di dongTang doanh thu quang cao di dong
Tang doanh thu quang cao di dongDuc Canh Tran
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3Kalluri Vinay Reddy
 
Hello android example.
Hello android example.Hello android example.
Hello android example.Rahul Rana
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...naseeb20
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfAbdullahMunir32
 
Android software development – the first few hours
Android software development – the first few hoursAndroid software development – the first few hours
Android software development – the first few hourssjmarsh
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
MAD mobile application development you can learn from here , we perform all c...
MAD mobile application development you can learn from here , we perform all c...MAD mobile application development you can learn from here , we perform all c...
MAD mobile application development you can learn from here , we perform all c...harshalpatil183931
 
MPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_DocumentationMPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_DocumentationXin Shao
 
Ios actions and outlets
Ios actions and outletsIos actions and outlets
Ios actions and outletsveeracynixit
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialAbid Khan
 
UI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms AppsUI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms AppsCodrina Merigo
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersAmbarish Hazarnis
 

Similar to Create New Android Activity (20)

Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
 
Build Your First Android App
Build Your First Android AppBuild Your First Android App
Build Your First Android App
 
Tang doanh thu quang cao di dong
Tang doanh thu quang cao di dongTang doanh thu quang cao di dong
Tang doanh thu quang cao di dong
 
Create an other activity lesson 3
Create an other activity lesson 3Create an other activity lesson 3
Create an other activity lesson 3
 
Hello android example.
Hello android example.Hello android example.
Hello android example.
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...Implementation of Push Notification in React Native Android app using Firebas...
Implementation of Push Notification in React Native Android app using Firebas...
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
How to create android push notifications with custom view
How to create android push notifications with custom viewHow to create android push notifications with custom view
How to create android push notifications with custom view
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Android software development – the first few hours
Android software development – the first few hoursAndroid software development – the first few hours
Android software development – the first few hours
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
MAD mobile application development you can learn from here , we perform all c...
MAD mobile application development you can learn from here , we perform all c...MAD mobile application development you can learn from here , we perform all c...
MAD mobile application development you can learn from here , we perform all c...
 
MPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_DocumentationMPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_Documentation
 
Ios actions and outlets
Ios actions and outletsIos actions and outlets
Ios actions and outlets
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
UI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms AppsUI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms Apps
 
Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - Beginners
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

Create New Android Activity

  • 1. Create New Activity ANDROID MOBILE APPLICATION TRAINING VIDEO - 3 Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 2. OVERVIEW In this tutorial, we will learn how to create new activity to an exisiting android project, send user input from one activity to another and add navigation button to the app bar for the user to return to parent screen. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 3. OPEN AN EXISTING PROJECT From your task bar/start menu, click open “Android Studio” In the Welcome to Android Studio window:  Click Open an existing Android Studio project. In the Open File or Project window:  Go to Android Studio Projects Folder and Select My Mobile App – the project we created in our earlier tutorial and click OK. Note: If you have not viewed our earlier tutorial – create new layout, please view that before starting this tutorial. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 4. OPEN MAIN ACTIVITY CLASS Android Studio main window appears after some process. We need to open MainActivity class (Jave file) – code behind the main_activity.xml: Click Open app > java > com.transposesolutions.mymobileapp > MainActivity. Add a Method “displayMessage” Note: This training material uses Android Studio v3.6.1. Package name “com.transposesolutions.mymobileapp” is our domain and app name, you should have your own package name. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 5. ADDING A METHOD We need to create the displayMessage() in the MainActivity class, this method will be used to start a new activity when app user clicks the submit button. Click open – app > java > com.transposesolutions.mymobileapp > MainActivity Add the following displayMessage() method stub inside AppCompactActivity: Note: You might see an error because Android Studio cannot resolve the View class used as the method argument. To clear the error, click the View declaration, place your cursor on it, and then press Alt+Enter, or Option+Enter on a Mac, to perform a Quick Fix. If a menu appears, select Import class. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 6. DEFINE - CLICK EVENT HANDLER Now, let us define the click event handler for the “Submit” button in the file activity_main.xml by adding the android:onClick: Open app > res > layout > activity_main.xml. Select the button in the Layout Editor. In the Attributes window, locate the onClick property Select “displayMessage” from its drop-down list. Now when the “Submit” button is tapped, the system calls the displayMessage() method. Note: We need to add few lines of code to the displayMessage(), so that the system can read the contents of the EditText (User input) and deliver that text to another activity which we will create next by adding a new activity to display the user input from main_activity_xml. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 7. ADD NEW ACTIVITY Let us add new activity to the project to display the user input from main_activity.xml. Please follow the following steps to add a new activity: In the Project window, right-click the app folder and select New > Activity > Empty Activity. In the Configure Activity window, enter "DisplayActivity" for Activity Name. Leave all other properties set to their defaults and click Finish. Now, main window appears after some processes with activity_display.xml opened with the layout editor. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 8. OPEN – LAYOUT EDITOR Let us open the layout editor, set the margin to the display_activity.xml: If your editor shows the XML source, click the Design tab. Click Select Design Surface and select Blueprint. Click Show in the Layout Editor toolbar and make sure that Show All Constraints is checked. Make sure Autoconnect is off. Click Default Margins in the toolbar and select your margin to “24”. If needed, you can adjust the margins for each view later. Click Device for Preview in the toolbar and select 5.5, 1440 × 2560, 560 dpi (Pixel XL). Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 9. ADD WIDGETS Let us add new UI string to app “app_message”, add the following widgets to the display_activity.xml and apply styles: TextView with ID: “welcome_message” – To display a welcome message and set the following: Set layout width: 0dp; layout margin top: 20dp Set widget property to “Center - Horizontally” Locate the text property, which is currently set to “Name” and delete the value. Then, click “Pick a Resource” and select “app_message” from the list. Set text gravity to “Center”; Set text size: 30 sp and text color: @color/colorAccent TextView with ID: “user_input” – To display the text entered by the app user in the main activity Set layout width: 0dp; layout margin top: 20dp Set widget property to “Center - Horizontally” and layout_constraint top to bottom Set text gravity to “Center”; Set text size: 30 sp and text color: @color/colorPrimary Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 10. ADD NAVIGATION Let us add a navigation button to app bar for the app user to return to main_activity.xml, to do that we need to declare “main_activity.xml is the parent screen in the AndroidManifest.xml:  Open the file at app > manifests > AndroidManifest.xml  locate the <activity> tag for DisplayMessageActivity replace <activity> tag with below code: Copyright © 2020 Transpose Solutions. All Rights Reserved. Next, we need to go back to MainActivity class file to add few lines of code to the displayMessage(), so that the system can read the contents of the field and deliver that text to display_activity.xml.
  • 11. USING - INTENT OBJECT Let us open MainActivity Class and add few lines of code to the displayMessage(), for this purpose, we use “Intent” object to start display_activity.xml and “putExtra()” method to add the user entered values from the “EditText” to Intent. Fill in the following code to displaymessage(), add SEND_MESSAGE constant and import required class: Note: For more technical documents about “Intent” can be accessed from Google developer guide: https://developer.android.com/reference/android/content/Intent Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 12. DISPLAYMESSAGE() Let us examine, what does the code we just added to the displayMessage(): The Intent constructor takes two parameters, a Context and a Class. The Context parameter is used first because the Activity class is a subclass of Context. The Class parameter of the app component, to which the system delivers the Intent, is, in this case, the activity to start. The putExtra() method adds the value of EditText to the intent. An Intent can carry data types as key-value pairs called extras. Your key is a public constant SEND_MESSAGE because the next activity uses the key to retrieve the text value. The startActivity() method starts an instance of the DisplayActivity that's specified by the Intent. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 13. DISPLAY USER INPUT To display the user input from main_activity.xml to display_activity.xml. For this purpose, we use Intent object and “getIntent()” method. Let us open DisplayActivity Class and fill in the following code to onCreate() Method and import required class : Now, we can run the app to view the changes we have done so far in this tutorial. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 14. RUN YOUR APP Use Android studio emulator to run your app: In the toolbar, select your app from the run/debug configurations drop-down menu.  From the target device drop-down menu, select the AVD that you want to run your app on.  Click Run Android Studio installs the app on the AVD and starts the emulator. Copyright © 2020 Transpose Solutions. All Rights Reserved.
  • 15. Conclusion We hope you were able to follow the instruction mentioned this tutorial, please find the final output of screen we developed so far: Copyright © 2020 Transpose Solutions. All Rights Reserved. Main_Activity.xml Display_Activity.xml
  • 16. Thank you for watching the video! We hope the training video 1, 2 and 3 was helpful. Please read the description of this video and external weblink provided to learn more… Copyright © 2020 Transpose Solutions. All Rights Reserved.