Catching the Lob

 

In Chapter 31, we showed how the service sends a broadcast to let the activity know a change was made to the forecast based on movement. Now, we can see how the activity receives and uses that broadcast.

Here are the implementations of and for :

 

Public onResume

Super onResume

 

RegisterReceiver

New IntentFilter

 

Public onPause

Super onPause

 

UnregisterReceiver

 

In , we register a static to receive matching the action declared by the service. In , we disable that , since we will not be receiving any such while paused, anyway.

The , in turn, simply arranges to update the forecast on the UI thread:

Private new BroadcastReceiver

Public onReceive

RunOnUiThread new Runnable

Public run

UpdateForecast

 

 

And uses the interface stub to call into the service and retrieve the latest forecast page, also handling the case where the forecast is not yet ready ():

Private updateForecast

Try

GetForecastPage

 

If null

PostDelayed new Runnable

Public run

UpdateForecast

 

Toast

MakeText this show

Else

LoadDataWithBaseURL null

Null

 

Catch final

OnServiceDisconnected null

 

RunOnUiThread new Runnable

Public run

GoBlooey

 

 

CHAPTER 32








Дата добавления: 2015-05-16; просмотров: 638;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.004 сек.