Listing 917 Opening a Toast on the GUI thread Available for

download on private void mainProcessing() {

Wrox.com Thread thread = new Thread(null, doBackgroundThreadProcessing,

"Background");

thread.start();

private Runnable doBackgroundThreadProcessing = new Runnable() { public void run() {

backgroundThreadProcessing();

private void backgroundThreadProcessing() {

handler.post(doUpdateGUI);

// Runnable that executes the update GUI method, private Runnable doUpdateGUI = new Runnable() { public void run() {

Context context = getApplicationContext(); String msg = "To open mobile development!"; int duration = Toast.LENGTH_SHORT; Toast.makeText(context, msg, duration).show();

INTRODUCING NOTIFICATIONS

Your applications can use Notifications to alert users without using an Activity. Notifications are handled by the Notification Manager, and currently have the ability to:

> Create new status bar icons

> Display additional information (and launch an Intent) in the extended status bar window

> Flash the lights/LEDs

> Vibrate the phone

> Sound audible alerts (ringtones, Media Store audio)

Using Notifications is the preferred way for invisible application components (Broadcast Receivers, Services, and inactive Activities) to alert users that events have occurred that may require attention. They are also used to indicate ongoing background Services —particularly Services that have been set to foreground priority.

As a user interface metaphor, Notifications are particularly well suited to mobile devices. It's likely that your users will have their phones with them at all times but quite unlikely that they will be paying attention to them, or your application, at any given time. Generally users will have several applications open in the background, and they won't be paying attention to any of them.

In this environment it's important that your applications be able to alert users when specific events occur that require their attention.

Notifications can be persisted through insistent repetition, being marked ongoing, or simply by displaying an icon on the status bar. Status bar icons can be updated regularly or expanded to show additional information using the expanded status bar window shown in Figure 9-3.

FIGURE 9-3

To display the expanded status bar view, click a status bar icon and drag it toward the bottom of the screen. To ' ' lock' ' it in place, ensure that you release your dra only after the window covers the entire screen. To hide it, simply drag it back upward.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment