Programming assignment

docx

School

University of the People *

*We aren’t endorsed by this school

Course

4405

Subject

Computer Science

Date

Nov 24, 2024

Type

docx

Pages

5

Uploaded by zainhas

Report
Programming assignment: Unit 4 University of the People CS 4405: Mobile Applications Instructor: Syed Mohsin Saif December 14, 2023 Part 1 Sign-Up Screen (activity_signup.xml): Create a layout file with text fields for name and email. Sign-Up Screen <!-- activity_signup.xml --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/editTextName" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter your name"/> <EditText android:id="@+id/editTextEmail" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter your email"/> <Button android:id="@+id/btnNext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Next"/> </LinearLayout> (SignUpActivity.kt): Validate the email and move to the next screen. // SignUpActivity.kt class SignUpActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_signup) val editTextName = findViewById<EditText>(R.id.editTextName) val editTextEmail = findViewById<EditText>(R.id.editTextEmail) val btnNext = findViewById<Button>(R.id.btnNext) btnNext.setOnClickListener { val name = editTextName.text.toString() val email = editTextEmail.text.toString() if (isValidEmail(email)) { // Save user data to database and move to the password setup screen moveToPasswordSetupScreen(name, email) } else { // Show error message for invalid email Toast.makeText(this, "Invalid email address", Toast.LENGTH_SHORT).show() } } } private fun isValidEmail(email: String): Boolean { // Add your email validation logic here return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() } private fun moveToPasswordSetupScreen(name: String, email: String) { // Implement navigation to the password setup screen // You can use Intent to start a new activity } }
Part 2 Explain how we make an internet connection in an android application. Demonstrate the same by developing a simple application that makes a successful network call and fetches some data from the internet. Handle the following exceptions so that the app does not crash: when there is no internet connection when the network request is unable to fetch data
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
To establish an internet connection in an Android application, you have the option of utilizing either the HttpURLConnection class or the HttpClient class. Nevertheless, starting from Android 6.0, HttpClient has been marked as deprecated in favor of HttpURLConnection, offering improved efficiency and simplicity. Below is a straightforward illustration demonstrating how to initiate a network call using HttpURLConnection while addressing potential exceptions. ( Developer-android, n.d). To perform network operations in your application, your manifest must include the following permissions: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> Example
REFERENCES Android Knowledge. (2022). Login page in Android Studio using Kotlin. https://www.youtube.com/watch?v=XMI1iejmtzs&t=160s Developer-android. (n.d). Connect to a network. https://developer.android.com/develop/connectivity/network-ops/connecting