Android Mobile application development - Event Handling (1).pptx
swethabollam11
4 views
28 slides
Mar 03, 2025
Slide 1 of 28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
About This Presentation
MAD IoT
Size: 872.39 KB
Language: en
Added: Mar 03, 2025
Slides: 28 pages
Slide Content
Android - Event Handling Events are a useful way to collect data about a user's interaction with interactive components of Applications. Like button presses or screen touch etc. The Android framework maintains an event queue as first-in, first-out (FIFO) basis. You can capture these events in your program and take appropriate action as per requirements.
There are following three concepts related to Android Event Management − Event Listeners − An event listener is an interface in the View class that contains a single callback method. Event Listeners Registration − Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Event Handlers − When an event happens and we have registered an event listener for the event, the event listener calls the Event Handlers.
Event Listeners Registration Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Using an Anonymous Inner Class Activity class implements the Listener interface. Using Layout file activity_main.xml to specify event handler directly.
Touch Mode Users can interact with their devices by using hardware keys or buttons or touching the screen.Touching the screen puts the device into touch mode. The user can then interact with it by touching the on-screen virtual buttons, images, etc. You can check if the device is in touch mode by calling the View class’s isInTouchMode () method.
Focus A view or widget is usually highlighted or displays a flashing cursor when it’s in focus. This indicates that it’s ready to accept input from the user. isFocusable () − it returns true or false isFocusableInTouchMode () − checks to see if the view is focusable in touch mode. (A view may be focusable when using a hardware key but not when the device is in touch mode) android:foucsUp ="@=id/ button_l "
Fragments A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments can't live on their own. They must be hosted by an activity or another fragment.
Modularity Fragments introduce modularity and reusability into your activity’s UI by letting you divide the UI into discrete chunks. fragments are better suited to define and manage the UI of a single screen or portion of a screen. Consider an app that responds to various screen sizes. On larger screens, you might want the app to display a static navigation drawer and a list in a grid layout. On smaller screens, you might want the app to display a bottom navigation bar and a list in a linear layout.
Fragment manager FragmentManager is the class responsible for performing actions on your app's fragments, such as adding, removing, or replacing them and adding them to the back stack.
Use the FragmentManager The FragmentManager manages the fragment back stack. At runtime, the FragmentManager can perform back stack operations like adding or removing fragments in response to user interactions. Each set of changes is committed together as a single unit called a FragmentTransaction .
Android Fragment Lifecycle Methods
Types of Fragments Single frame fragments : Single frame fragments are using for hand hold devices like mobiles, here we can show only one fragment as a view. List fragments : fragments having special list view is called as list fragment Fragments transaction : Using with fragment transaction. we can move one fragment to another fragment.
Handling the Fragment Lifecycle A Fragment exist in three states: Resumed : The fragment is visible in the running activity. Paused : Another activity is in the foreground and has focus, but the activity in which this fragment lives is still visible (the foreground activity is partially transparent or doesn’t cover the entire screen). Stopped : The fragment is not visible. Either the host activity has been stopped or the fragment has been removed from the activity but added to the back stack. A stopped fragment is still alive (all state and member information is retained by the system). However, it is no longer visible to the user and will be killed if the activity is killed.