How to change the back button behaviour

Sometimes, when developing Android applications, there is a need to override the default behaviour of the back button which means assigning another behavior for the ‘Back’ button. Although changing the behaviour of back button is not recommended, but there are some situations where changing the ‘back’ button behavior is mandatory, such as to avoid accidentally finishing or closing the current Activity.

For example, a text editor, should confirm if the user really wants to quit without saving the current changes, or a game, that check if it is the player’s intention to close the current game session.

Read More

How to change screen brightness programmatically

This post will explain you how to change the current system brightness with a seek bar on Android devices. The application which we are going to develop will work only on real devices, because it is impossible to see the brightness changes on the emulator.

One thing you must know is that Android system brightness value is applied to the screen’s backlight only when the screen turns on. This means that only after a device boots up or awaking the phone from a sleeping state will make the screen as bright as the value defined by the System.SCREEN_BRIGHTNESS variable. Consequently, changing only that variable won’t be enough to preview the brightness level as the brightness value need to be set for the window.

Read More

Android Intent example

Have you ever thought how you are navigated from one screen to another in Android application? Here is the answer. Intent – a jargon in Android is doing all the work at background. Go through the post, you will learn how to navigate from one screen to another.

What is Intent?

  • Intents are system messages, running around the inside of the device, notifying applications of various events, from hardware state changes (e.g.,an SD card was inserted), to incoming data (e.g., an SMS message arrived),to application events (e.g., your activity was launched from the device’s main menu).
Read More

Android notifications example

What is android notifications?

Definition from Android developers site:

A status notification adds an icon to the system’s status bar (with an optional ticker-text message) and a notification message in the notifications window. When the user selects the notification, Android fires an Intent that is defined by the Notification(usually to launch an Activity). You can also configure the notification to alert the user with a sound, a vibration, and flashing lights on the device.

What are we going to develop?

The application which we are going to develop will have two buttons – one to trigger notification and other to clear the triggered notification.

Read More

Android LinearLayout example

What is Android layout?

Layout denotes the architecture of the application, where and how the controls should be organized in the UI.It defines the layout structure and holds all the elements that appear to the user.

Android allows us to create layouts for the applications using simple XML file and those layouts must be placed in /res/layout folder.

We can declare the layout in two ways and here we will discuss first way of doing it:

  1. Declare UI elements in XML
  2. Create UI elements at runtime using Java.
Read More

Pin It on Pinterest