0% found this document useful (0 votes)
2 views

Lab 4

The lab journal details the implementation of layouts and activities in an Android application using Android Studio. It includes coding examples for activity lifecycle methods and XML layout design using Linear and Constraint Layouts. The conclusion highlights the successful application of these concepts through the lab tasks.

Uploaded by

m faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab 4

The lab journal details the implementation of layouts and activities in an Android application using Android Studio. It includes coding examples for activity lifecycle methods and XML layout design using Linear and Constraint Layouts. The conclusion highlights the successful application of these concepts through the lab tasks.

Uploaded by

m faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Software Applications for

Mobile Devices Lab


SEL-448

Lab Journal: 4

Name: Muhammad Faisal


Class: BCE-8.
Enrollment no: 01-132182-036.
Submitted to: Eng. AMNA WAHEED
Lab No. 4
Layout and Activities
Software Used: Android Studio
Objective:
 Understanding and implementation of Layout and Activities in an Android Application
Introduction:
Layouts:
A layout defines the structure for a user interface in your app, such as in an activity. All elements
in the layout are built using a hierarchy of View and ViewGroup objects. A View usually draws
something the user can see and interact with. Whereas a ViewGroup is an invisible container that
defines the layout structure for View and other ViewGroup objects, as shown in figure given
below.

The View objects are usually called "widgets" and can be one of many subclasses, such as
Button or TextView. The ViewGroup objects are usually called "layouts" can be one of many
types that provide a different layout structure, such as LinearLayout or ConstraintLayout .
Activity:
The Activity class is a crucial component of an Android app, and the way activities are launched
and put together is a fundamental part of the platform's application model. Unlike programming
paradigms in which apps are launched with a main() method, the Android system initiates code
in an Activity instance by invoking specific callback methods that correspond to specific stages
of its lifecycle shown in given figure.
Task No.1: Implement All activities callback functions and print to log when they are
called.
Coding:
package com.example.lab04;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import
android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}
@Override protected void
onStart() { super.onStart();
Log.d("MainActivity", "OnStart Called");
}
@Override protected void
onPause() {
super.onPause();
Log.d("MainActivity", "OnPause Called");
}
@Override protected void
onResume() {
super.onResume();
Log.d("Main Activity", "OnResume Called");
}
@Override protected void
onStop() { super.onStop();
Log.d("MainActivity", "OnStop Called");
}
@Override protected void
onRestart() {
super.onRestart();
Log.d("MainActivity", "OnRestart Called");
}
@Override protected void
onDestroy() {
super.onDestroy();
Log.d("MainActivity", "OnDestroy Called");
}}
Output:

Task No.2: Create the following layout using Linear and Constraint Layout.
Coding:
XML File:
<?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=".MainActivity"
android:orientation="vertical"
>

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

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"

android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_launcher_background" />

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My Android Application"
android:layout_marginRight="100dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="130dp"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">

<Button
android:id="@+id/button12"
android:layout_width="153dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:text="Hello" />

<Button
android:id="@+id/button13"
android:layout_width="141dp"
android:layout_height="wrap_content"
android:text="World" />

</LinearLayout>

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

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:layout_marginLeft="150dp"
android:text="Made by:" />

<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="130dp"
android:text="M Faisal" />
</LinearLayout>

</LinearLayout>

Output:

Conclusion:
In this lab we learned how to implement the concepts of layouts and activities. We used these
concepts in the given tasks and completed them successfully.

You might also like