App Mob
App Mob
Definition:
An Application: un logiciel applicatif conçu pour s’exécuter à partir du système
d’exploitation.
Operation Systems:
Un système d’exploitation mobile est un ensemble de programmes qui gère les opérations, le
contrôle, la coordination, l'utilisation du matériel et le partage des ressources d'un appareil
entre les programmes qui s'y exécutent. C'est une plateforme logicielle permettant aux
applications de fonctionner sur des appareils mobiles. Il est important de noter que les
systèmes d’exploitation mobiles varient en fonction des fonctionnalités qu'ils prennent en
charge.
Characteristics:
regroupe un ensemble des fonctionnalités; dont: la gestion de la mémoire, des
microprocesseurs et l’ordonnancement, de systèmes de fichiers, des I./O., de sécurité, de
fonctionnalités multimédia, etc.
Android:
Based on Linux, owned by Google, runs on phones, TVs, cars, smart glasses, etc.
It is open source, free, easy to develop applications on (because of the many near-perfect,
easy to access APIs), easy to sell (GooglePlay), flexible (can run on many structures).
Structure:
Is based on: Linux Kernel, libraries, the application development module, and the different
applications.
Kernel: Le noyau est l’élément du système d’exploitation qui représente la passerelle entre la
partie matérielle et la partie logicielle. It is Linux. It manages the basic layers: material and
the operations directed to them. The kernel used is developed to fit the Android mobile
exclusively, with advanced power management.
Libraries: many libraries in c/c++ offering advanced services.
L’environnement d’exécution (Android runtime): similar to Java’s virtual machine concept,
but it’s lighter, and found on the same level as libraries. Android apps must be compiled using
“dx”, which compiles .java into .class, and .class into .dex, a Dalvik Executable. This is not
used after android 5.0 came out, but uses Android Runtime (ART) instead, which is not a VM.
DVM (Dalvik VM) is good because it offers portability (it is used to run Java bytecode),
security, and memory management.
Application Framework: uses libraries to offer components for developers, it offers two types
of services:
● Core Platform services: services are applications which run in the background. These
contain essential services:
○ Activity manager: manages the life cycle of activities, and the navigation pile
stack.
○ Package manager: used by Act Man to load information from the .apk
○ Window manager: which window must appear next to another.
○ Resource manager: images, files, audios, etc.
○ View system: graphical components.
● Hardware services: access to hardware API.
○ Telephony services: manages access to telephonic services (GSM, 3G, etc.)
○ Location services: access to GPS interface.
○ Bluetooth services: access to interface.
○ Wi-Fi services: same.
○ USB services: same.
○ Sensor services: access to sensors.
Application & widgets: group of android apps.
Development environment:
Whether it be Eclipse + JDK + SDK, or Android studio, which is based on IntelliJIDEA, it
allows for Koten/Java/XML files and graphic visualization. It consists of two repositories.
First one: App:
A file tree to organize the structure, and simplify the dev process, contains:
● Manifest: XML file describing the app and its components, such as activities, services,
etc.It also specifies various options such as: the hardware requirements, certain
security settings, icon, file’s name, etc. It can be considered to be the application’s ID
card, and that which authorizes activities to run.
● Java/Kotlen: contains Source code.
● Res: resources such as images, GUI views, etc.
The chapter began with an overview of embedded systems, which are fundamental to mobile
operating systems. It then detailed Android's inception, versions, and architecture. The final
section focused on Android development environments, methods, and the structure of an
Android Studio project. The upcoming chapter will delve into the essential elements of
mobile applications, crucial for their construction.
Activities:
*Usually, all apps follow a similar structure, with each window serving a specific function
called “activity”. An activity is what links between the User Interface (UI) and the backend
code, you can tell that the activity has changed if the UI completely changes, so for us: the
activity is the window we are visualizing, e.g., the UI change when you click on the return
button, or a youtube video.
*Activities also contain information about the current state of the application, known as the
“context”, which connects the OS with the activities within the app.
*Interface = {Layouts + Views}, layouts define the structure and layout (linear layout, relative
layout, etc.) to organize Views within an activities and fragments. Views are the UI interactive
components, e.g., buttons.
Activity Status:
It can vary based on priorities and system resources. When an application is launched, it
occupies the top of the activity stack (la pile), and the visible activity is the one the user
interacts with. If a new activity with higher priority takes the top of the stack, replacing the
current activity, then the old activity will reappear when the activities above it are stopped.
An activity can exist in three states primarily distinguished by their visibility:
1. Active: The activity is at the top of the stack and fully visible. It represents the current
application, receiving the user's full attention and being fully usable.
2. Paused: Users do not directly interact with the activity. Typically, it remains partially
visible (i.g., when a notification arrives, a semi-transparent window appears in front
of the current activity to show the message content and allow a response). At this
stage, the application loses focus to the one above it. To regain focus, the user must
dismiss the top application, enabling direct interaction with the activity. If memory is
needed, the system may eventually close the application.
3. Stopped: This means the activity is completely invisible on the screen, and the
application no longer holds focus, and the system keeps a small portion of its memory
to retain its state in case of re-opening.
Control center (hadik l3fsa ta3 notification etc) is a part of the OS, it may be a fragment.
onCreate(): called when the activity starts, it initializes the views and starts background
tasks, taking a Bundle as a parameter that contains the previous state of the activity. A bundle
is a container for a collection of data, typically used for passing data between activities.
onStart(): Indicates the effective start of the activity, it can be called by the onRestart method.
(consult the figure)
onResume(): it runs right after onStart(), or after a short pause, it executes necessary
operations for the activity to function again, initializes the variables and listeners. These
operations should be paused during the onPause method and resumed during subsequent
onResume() method. Note that it uses the Bundle when resuming.
onPause(): If another activity comes to the foreground, the current activity is paused, and just
before onPause, a call to the onSaveInstanceState() method is made to save important
information.
The onPause() actually halts (stops) all operations of the activity if it is not visible, and
corresponds to a call to onResume if the activity becomes visible again.
Passing to Stopped Status: a call to the onStop method, and halts all remaining operations.
What's after the Stopped Status: the act can be resumed with onRestart followed by the
normal lifecycle, or can be terminated with a call to the onDestroy(), which halts all
remaining operations, closes database connections, threads, open files, etc. It’s a killer.
Resources:
refers to any element or asset used in a system, program, or application, it takes many forms
and serves different purposes, i.g., hardware, files, source code, libraries and functions, data,
network, etc.
Key Aspects:
Elements, their interactivity (interactions), their reactivity (speed), their disposition
(coherent and logical disposition), and aesthetic look.
Intent:
A messaging object for requesting actions or broadcasting events. It facilitates
communication between different components and the system, allowing for launching
activities, interacting with other apps, and exchanging data seamlessly.
Main Usages:
Explicit Intent: use it to launch specific components within your app by explicitly specifying
the class name.
Implicit Intent: use it to perform actions without explicitly specifying the component to start,
Android system automatically selects the appropriate component.
Intent with data: Use: Allows transmission of data between application components.
Implicit Intent for Image Selection: Opens an application enabling the user to select an image.
Fragments:
A fragment, unlike an activity, represents only a portion of an application's user interface. It
can be considered as a reusable component that can be integrated into different activities to
create a flexible and dynamic user interface [during runtime], it can be static as well.
Characteristics:
Reusability (can be integrated in different activities, without redundancy issues), integration
flexibility, ease of communication amongst each other and with the app’s components
(flexibility ++), and independent life cycle: precise state control and optimal resource
management.
Communications:
Two main methods: through the host activity by using it as a mediator, this method is useful
for handling interactions that involve multiple fragments or require coordination between
them but do not need direct communication between the fragments themselves. I.g., when
fragment A is selected, the item’s (i.g., the T-Shirt) details are displayed in fragment B.
Direct communications: good for specific and fast interactions.
Usage:
Pure XML: Right click the package folder -> New -> Fragment => Fragment (blank), name it,
and finish. Now head to the fragment’s XML file, and customize your fragment, adding text
and buttons and whatnot. Now go to the fragment’s Java file, implement the algorithms. Now
go to the main_activity.xml file, and add your fragment using
android:name=“com.example.myapp.[FragmentName]”, with FragmentName being identical to
the fragment’s java file.
BackStack:
Use BackStack to allow users to return using the return button, enhancing the UX:
fragmentTransaction.addToBackStack(null); use this post replacement / addition / deletion.
Barre d’Action:
Located at central top, for frequently done actions, define it using Toolbar element:
Animations:
Dynamic visual techniques to enhance the UX. it can be a transition, commonly used to
transition activities, we have the transition (fade in/out or slide in/out or drop in/out):
A simple rotation:
Scaling (Echelle):
Fading (fendu) animation:
Persistence:
1) Activity’s data persistence: Saves the user’s journey through the app, and maintains
the UI status in case of his return.
2) Key=value: using it to store preferences, configuration, and acts’ status in a file.
3) File System usage: since files are the primitive way of storing in Android, external or
key=value 🤷🏻♂️
internal storage drives can be used. Manich fahem the diff between it and the
Préférence Partagées:
A mechanism to store and restore data using key=value pairs, used on preferences, config,
etc. of simple data.
Goal: a simple and fast mean of storing lightweight data, with easy access to this data.
To restore:
Files:
Code Source:
Including Java/Kotlen files, or Swift/Objective-C for iOS, which define the app’s comportment.
Assets (fichiers de resources):
Static files such as images, icons, config files, etc. in a “res” folder in android or “Assets” in
iOS, and integrated in the application while executing.
Layouts (mise en page): XML
Define the layout’s structure and representation, and element disposition.
Manifest files:
AndroidManifest.xml, or Info.plist for iOS, contain crucial information such as the needed
permissions, components, services, etc.
Local Data files:
Can be an SQLite DB, or shared preferences files, or a totally different format specific for the
application.
Config files:
Such as properties files, JSON config files, etc. They are usually used to parametrize the app’s
behavior.
Logs (journal):
Generated while executing, good for debugging and monitoring.
APK, IPA:
When the app is developed, it is gathered in an installation file (APK for android and IPA for
iOS).
Certificates and keys files:
Remember security? Asymmetric algorithms’ keys and certification? Exactly. To secure the
network communications with secured services.
XML:
- I skipped many slides-
They are used for: behavior configuration, data exchangement, and as a universal language.
TP1:
New project -> Empty Activity -> name, package name, save location, language, minimum
SDK to use -> DONE! The IDE will have the project’s tree on the left, and the code on the
main part of the screen, along with the tabs and some information at the bottom.
Project creation results in an activity + a screen, showing “hello world!”, you can compile it
with the menu: Build -> make project, ctrl+f9, or the hammer green button. You shall see a
notification at the bottom “Gradle build running”.
You can run it by Run->run app, Maj+F10, or green play button. If you run before compiling, it
will compile first then run, make sure you've connected your phone to run it or a VM, which
will consume resources.
To set up a virtual machine, click on the phone icon at the top bar -> create device -> choose
an Android Virtual Device -> OS version -> finish. Now re-run.
It has an execution console, called logcat, at the bottom.
If you change the .java file, you should update the manifest file, this line particularly:
<activity android:name=".NewMainActivity">
Texts are found in the XML file in a <TextView/>,
Translate:
Can be done manually in the res/values/string.xml file, and create additional files:
values-fr/string.xml, values-en/string.xml, values-du/string.xml for german. Or with the GUI by
right clicking on the string.xml file -> Open Translations Editor -> adding a language -> giving
translated texts.
Icon:
Right click on “app” directory -> New -> Image Asset -> configure your icon’s settings & select
an image and there you go :) save n leave, actually don’t leave, go to AndroidManifest.xml ->
locate the <application>, find android:icon attribute, change this to your icon’s name
without the extension: android:icon="@drawable/new_icon", you will choose the name when
changing the icon.
If you delete an icon, or all icons, android studio (AS) will automatically update
AndroidManifset.xml for you, usually, but you can double check that the android:icon is
pointing towards the right element.
NOTE: from the official website: Jan 3, 2024 — The name can contain lowercase characters,
underscores (_), and digits only. Trim - To adjust the margin between the icon graphic and
border in the ...
First TP is completed successfully.
TP2:
Every seen element is called a view, which is a location expressed using left and top
coordinates, and length and width dimensions, in density pixel (dp), which is the number of
pixels within a given area on a display screen, higher DP = more clarity.
It can be: texts, inputs, buttons, or a ViewGroup such as that contain views and manage the
layout.
ViewGroup:
Containers and sometimes layout managers, they are the parents for child views
ConstraintView: create complex layouts by defining relationships (constraints) between views
[or screen border].
ScrollView: scrolls down if the child element is bigger than the screen, can have exclusively
one child.
RecyclerView: same as scrollView, but allows for dynamic child addition and deletion, which
optimizes the performance by reducing the total views, but it requires a layout manager.
LinearLayout example:
ToolBar:
Attributes:
You will see this:
1) Layout_height,
2) Layout_width
3) Close attributes.
The 8 indicates the margin.
The first two can have three values:
wrap_content means that the layout’s size will
adapt to its content., and match_constraint so
the child element will be made to fit the parent,
and a defined fixed size in Density Pixels.
Tip: When changing layout_width, if no
dimension is specified, it defaults to zero, similar
to match_constraint, the UI element can expand
to meet the specified constraints and margins.
XML version:
Attributes are set in this format:<android: attr_name=“value”, if the value is a resource then:
<android: attr_name=“@resource”, i.g., android:background="@color/myBackgroundColor,
noting that the bg color is already defined. To refer to a View’s attribute: android:
id=@+id/attr_name, the @+id means create a new resource of type ID called attr_name, and
assign it to the View element, then use this ID to refer to the resource.
To refer to a view, just remove the “+” sign.
Layout Variants:
You can rotate the screen to visualize it in that mode, or select another device. To make a
variation: drop down the rotation icon button -> Create Landscape Variation, this will create a
land/activity_main.xml, a variant for the landscape orientation, you can now modify this view
and the portrait orientation will stay intact. You can see `res/layout/activity_main.xml(land)`
underneath the old one.
To create a device variant (for tablet or whatnot): Orientation for preview -> Create a tablet
variant (wella 3fsa hka) then get going. You will find new files just like before.
Relative Layout:
It uses these attributes: android; layout_[ toLeftOf | toRightOf | centerHorizontal |
center_vertical | align_parentTop | align_parentBottom]=“@ID_of_some_element”, you
say that this element’s left or right of @ID element, or horizontally/vertically regarding the
parent, or attach the top/bottom of this element to the top/bottom of its parent, respectively.
It has others, the teacher said: voir le cours, however, these were not mentioned, I assume
that this is chapter 4+ ?