0% found this document useful (0 votes)
22 views29 pages

Mad Vii

Uploaded by

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

Mad Vii

Uploaded by

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

Android App.

Components

❑All the application components are defined in the android app description file
(AndroidMainfest.xml)
❑In flutter, this file provides the Android operating system with important
information about your app, such as its components, permissions, and
configurations.
❑The basic core application components that can be used in Android application:
•Activities
•Intents
•Content Providers
•Broadcast Receivers
•Services
1
Key Components of AndroidManifest.xml

•Root Element: <manifest> - This is the root element that includes the package
name and XML namespace.
•Application Element: <application> - Defines global attributes for the entire app,
including app icons, themes, and more.
•Activity Declaration: <activity> - Specifies an activity, which is a single screen in
an Android app. The main activity typically has an intent filter to declare it as the
entry point.
•Permissions: <uses-permission> - Declares the permissions your app needs, such
as internet access or access to the camera.
•Meta-data: <meta-data> - Used to pass additional data to the Android system,
which can be utilized by your app.

2
AndroidManifest.xml
❑Every application must have an • It declares which permissions the application
AndroidManifest.xml file (with precisely that must have in order to access protected parts of
name) in its root directory. the API and interact with other applications.
❑It presents essential information about the • It also declares the permissions that others are
application to the Android system, information required to have in order to interact with the
the system must have before it can run any of application's components.
the application's code. • It lists the Instrumentation classes that provide
profiling and other information as the
❑Among other things, the manifest does the
application is running. These declarations are
following:
present in the manifest only while the
• It names the Java package for the application. application is being developed and tested;
The package name serves as a unique they're removed before the application is
identifier for the application. published.
• It describes the components of the • It declares the minimum level of the Android API
application. that the application requires.
• It determines which processes will host • It lists the libraries that the application must be
application components. linked against.

3
• In the example code for the temperature converter app, we didn't
explicitly show the AndroidManifest.xml file because it wasn't directly
relevant to the Dart code and widget lifecycle.
• However, for a complete Flutter app, the AndroidManifest.xml is
always part of the project setup to ensure proper integration with the
Android platform.

4
AndroidManifest.xml file
Every activity you have in your application must be declared in your AndroidManifest.xml file, like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activity_lifecycle">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Activity_lifeCycle">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

By including encoding="utf-8", you ensure that the XML parser correctly interprets the text, including any special
characters or symbols that might be used in your app's configuration.
It is used to avoid name conflicts by distinguishing between elements that may have the same name but are used
in different contexts.
5
Understanding Activities

❑ An Android application can have zero or more activities.


❑ The main purpose of an activity is to interact with the user
❑ From the moment an activity appears on the screen to the moment
it is hidden, it goes through a number of stages. (life cycle).
❑ Think of fragments as “miniature” activities that can be grouped to
form an activity
❑Instead of activities, Flutter uses widgets to build the UI and manage
the app's state.

6
Understanding Activities

•Your activity class loads its user interface (UI) component using the
XML file defined in your res/
•layout folder. In this example, you would load the UI from the
main.xml file:
•setContentView(R.layout.activity_main);

7
Activity life cycle
+------------------> onCreate
| |
| v
+----+---------> onStart
| | |
| | v
+----+---------> onResume
| | |
| | v
| +<--- onPause---+
| | |
| v v
| onStop onRestart
| | |
| v v
+--> onDestroy <-----+
The Activity base class defines a series of events that govern the life
cycle of an activity. Every activity you have in your application must be declared in
your AndroidManifest.xml
8
In Flutter, which uses the Dart programming language, the activity lifecycle can be
understood through the lifecycle of widgets. Some of the key stages of a Flutter widget
lifecycle:
Initialization:
initState(): Called when the widget is first created. This is where you should do one-
time initializations.
Building:
build(): Called whenever the widget needs to be rendered. It can be called multiple
times during the lifecycle, depending on the state of the widget.
State Changes:
setState(): Used to notify the framework that the internal state of this object has
changed.
Update:
didUpdateWidget(): Called whenever the widget configuration changes, providing an
opportunity to update the state of the widget.
• Cleanup:
dispose(): Called when the widget is removed from the widget
tree permanently. It is used to clean up resources.
Other Lifecycle Methods:
reassemble(): Called whenever the application is reassembled
during development, typically triggered by hot reload in Flutter
.didChangeDependencies(): Called when an inherited widget in
the widget tree changes, triggering a rebuild.
Function: This method is called once when the widget is created. It is
used for one-time initializations such as setting up streams, fetching
initial data, or other setup tasks.
@override
void initState() {
super.initState();
// Initialization code here
}
State Changes

setState()
Function: This method is used to update the widget's state and trigger
a rebuild. It takes a callback function where you can modify the state.
void _updateState() {
setState(() {
// Update the state here
});
}
Building

build()
Function: This method is called whenever the widget needs to be rendered. It returns a Widget that
will be displayed on the screen. It can be called multiple times during the widget's lifecycle,
especially when the state changes.
@override
Widget build(BuildContext context) {
// Build the UI
return Scaffold(
appBar: AppBar(
title: Text('Title')),
body: Center(child: Text('Hello, Flutter!’)),
);
}
Dependencies

didChangeDependencies()
Function: Called when a widget’s dependencies change. This method is
useful when you need to update the widget based on changes in its
dependencies.
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Code to handle dependency changes
}
Update
didUpdateWidget(covariant <WidgetType> oldWidget)
Function: Called whenever the widget configuration changes. This
allows you to compare the old widget configuration with the new one
and update the state accordingly.
@override
void didUpdateWidget(covariant MyWidget oldWidget) {
super.didUpdateWidget(oldWidget);
// Code to handle widget update
}
Reassemble

reassemble()
Function: Called during development when the application is being
reassembled, usually due to a hot reload.
@override
void reassemble() {
super.reassemble();
// Code to handle reassembly
}
Cleanup
dispose()
Function: Called when the widget is permanently removed from the
widget tree. It is used to clean up resources such as streams,
controllers, or other objects that need to be disposed of.
@override
void dispose() {
// Clean up resources here
super.dispose();
}
my_flutter_app/
├── android/
│ ├── app/
│ │ ├── src/
│ │ │ ├── main/
│ │ │ │ ├── AndroidManifest.xml # Manifest file
│ │ │ │ └── java/
│ │ │ │ └── com/
│ │ │ │ └── example/
│ │ │ │ └── my_flutter_app/
│ │ │ │ └── MainActivity.java # Main Activity
│ ├── build.gradle # Project-level build file
│ └── gradle/
├── lib/
│ ├── main.dart # Dart entry point
└── pubspec.yaml # Flutter configuration
Activities Intents
❑In android, Intent is a messaging
❑An activity represents a single screen with a object which is used to request an
user interface (UI) and it will acts an entry action from another component.
point for the user’s to interact with app.
❑In android, intents are mainly used to
❑ For example, a contacts app that is having perform the following:
multiple activities like showing a list of • Starting an Activity
contacts, add a new contact, and another
activity to search for the contacts. • Starting a Service
• Delivering a Broadcast
❑All these activities in the contact app are
independent of each other but will work ❑There are two types of intents
together to provide a better user experience. available in android, those are
• Implicit Intents
• Explicit Intents

19
Services Broadcast Receivers
❑Service is a component that keeps an app ❑Broadcast Receiver is a component that will
running in the background to perform long allow a system to deliver events to the app
running operations based on our requirements. • sending a low battery message to the app.
❑For Service, we don’t have any user interface ❑The apps can also initiate broadcasts to let
and it will run the apps in background other apps know that required data available
• play music in background when the user in in a device to use it.
different app. ❑Generally, we use Intents to deliver
❑These are the three different types of services: broadcast events to other apps and
❑Foreground Broadcast Receivers use status bar
❑Background notifications to let the user know that
broadcast event occurs.
❑Bound

20
Content Providers

❑Content Providers are useful to exchange the data between the apps based on
the requests.
❑It can share the app data that stores in the file system, SQLite database, on the
web or any other storage location that our app can access.
❑By using it, other apps can query or modify the data of our app based on the
permissions provided by content provider.
❑For example, android provides a Content Provider (ContactsContract.Data) to
manage contacts information, by using proper permissions any app can query
the content provider to perform read and write operations on contacts
information.

21
Additional Components

There are additional components used to build the relationship between the previous components to
implement our application logic:
Component Description

Fragments These are used to represent the portion of user interface in an activity

Layouts These are used to define the user interface (UI) for an activity or app

Views These are used to build a user interface for an app using UI elements like buttons, lists, etc.

Resources To build an android app we required external elements like images, audio files, strings, dimens, etc. other than coding

Manifest File It’s a configuration file (AndroidManifest.xml) for the application and it will contain the information about activities, intents, content
providers, services, broadcast receivers, permissions, etc.

22
Android UI
➢the basic unit of an Android application is an activity, which displays the UI
of your application.
➢ The activity may contain widgets such as buttons, labels, textboxes, and so
on. Typically, you define your UI using an XML file
➢During runtime, you load the XML UI in the onCreate() method handler in
your Activity class, using the setContentView() method of the Activity class:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

23
Views
➢An activity contains views and ViewGroups.
➢A view is a widget that has an appearance on screen.
➢ Examples of views are buttons, labels, and text boxes.
➢A view derives from the base class android.view.View.

24
ViewGroups
➢One or more views can be grouped into a ViewGroup.
➢A ViewGroup (which is itself a special type of view) provides the layout in which
you can order the appearance and sequence of views.
➢Examples of ViewGroups include RadioGroup and ScrollView.
➢A ViewGroup derives from the base class android.view.ViewGroup.

25
Layouts
➢ Another type of ViewGroup is a
Layout.
The Layouts available in Android
➢ A Layout is another container that are as follows:
derives from ➢ FrameLayout
android.view.ViewGroup and is
used as a container for other ➢LinearLayout(Horizontal)
views. ➢LinearLayout(Vertical)
➢ However, whereas the purpose of ➢TableLayout
it is to group views logically
➢TableRow
➢ such as a group of buttons with a
similar purpose ➢GridLayout
➢ Layout is used to group and ➢RelativeLayout
arrange views visually on the ➢ConstraintLayout
screen.

26
FrameLayout
➢ Framelayout is
a ViewGroup subclass that is used
to specify the position
of View instances it contains on
the top of each other to display
only single View inside the
FrameLayout.
➢ simply, FrameLayout is designed
to block out an area on the screen
to display a single item.
➢ Following representation of frame
layout in android applications.

27
FrameLayout Cont.
➢FrameLayout will act as a placeholder on the screen and it is used to
hold a single child view.
➢In FrameLayout, the child views are added in a stack and the most
recently added child will show on the top.
➢multiple children views can be added to FrameLayout and control
their position by using gravity attributes in FrameLayout.

28
LinearLayout(Horizontal ,
Vertical)
➢ LinearLayout is ➢ In LinearLayout, the child View
a ViewGroup subclass which is instances arranged one by one, so
used to render all the horizontal list will have only
child View instances one by one one row of multiple columns and
either in Horizontal direction or vertical list will have one column of
Vertical direction based on the multiple rows.
orientation property.
➢ we can specify the linear layout
orientation
using android:orientation attribute
.
➢ Following is the pictorial
representation of linear layout in
android applications.

29

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy