Professional Documents
Culture Documents
External Resources and Activity: by Zana Azeez Kakarash Email: 2021 - 2022
External Resources and Activity: by Zana Azeez Kakarash Email: 2021 - 2022
by
Zana Azeez Kakarash
Email: zana.azeez@kti.edu.krd
2021– 2022
Three
Externalizing Resource
• Android supports the externalization of resources, ranging from simple values such as strings and
colors to more complex resources such as images, animations, themes, and menus.
• By externalizing resources, you make them easier to maintain, update, and manage
• To include different resources to support variations in hardware - particularly , screen size and
resolution.
5
Externalizing Resource
- findViewByID()
- getResources()
Android uses @ symbol to call all the types of access in XML files
method.
<ImageView android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/exit" />
</LinearLayout>
10
Android - UI Layouts
• The basic block for user interface is a View object which is created from the View class.
• Views are used to create interactive UI components like buttons, edittext, textview etc.
• The ViewGroup class called "layouts," which are different kinds of layout architecture, like linear,
• The most common way to define your layout and express the view is with an XML layout file.
• View objects are leaves in the tree, ViewGroup objects are branches in the tree.
22
Measurements in layout
• You will use one of these constants to set the width or height :
android:layout_width = match_parent
tells your view to become as big as its parent view.
android:layout_width = wrap_content
tells your view to size itself to the dimensions required by its content.
• Here width and height can be specified in terms of dp (Density-independent Pixels), sp ( Scale-
independent Pixels), pt ( Points which is 1/72 of an inch), px( Pixels), mm ( Millimeters) and finally
in (inches).
• A view object may have a unique ID assigned to it which will identify the View uniquely within the tree.
• The syntax for an ID, inside an XML tag is : android:id = " @ + id / btn "
• The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and
• The plus-symbol (+) means that this is a new resource name that must be created and added to our
resources.
25
Activity
• An Activity is an application component that provides a screen with which users can interact in
order to do something, such as dial the phone, take a photo, send an email, or view a map.
• The activity’s content view or user interface is initialized using the setContentView() method
• While application is running, we create new Activities and close old ones, hide the application and open it again
and so on, and Activity can process all these events it is required and it can be in one of four states :
1) Resumed - Activity is visible on the screen, it is focused and the user can interact with it. This state is
sometimes called Running.
2) Paused - Activity is not focused, user cannot interact with it, but it is visible (it is covered by another Activity,
which is transparent)
3) Stopped - Activity is not visible, that is, it is not focused and user cannot interact with it . We can wake up an
stopped activity up by using "Notification" or multi-task button.
4) Dead - The activity has been finished manually, or garbage collected by system.
• Implementing your activity lifecycle methods properly ensures your app behaves well in several
ways, including that it :
a) Does not crash if the user receives a phone call or switches to another app while using your app.
b) Does not lose the user's progress if they leave your app and return to it at a later time.
c) Does not crash or lose the user's progress when the screen rotates between landscape and
portrait orientation.
• System calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or
"main") activity.
• You can define which activity to use as the main activity in the Android manifest file, AndroidManifest.xml .
• The main activity for your app must be declared in the manifest with an <intent-filter> that includes the MAIN
• For example:
31