/** Factory method that returns an explicit Intent for downloading an image. */ public static Intent makeIntent( Context context, int requestCode, Uri url, Uri directoryPathname, Handler downloadHandler) { // Create an intent that will download the image from the web. // TODO -x- you fill in here, replacing "null" with the proper // code, which involves (1) creating a RequestMessage // containing the various parameters passed into this method // and (2) storing this RequestMessage as a Message "extra" in // the Intent. RequestMessage requestMessage = RequestMessage.makeRequestMessage( requestCode, url, directoryPathname, new Messenger(downloadHandler)); Intent intent = new Intent(context, DownloadImagesStartedService.class); intent.putExtra(REQUEST_MESSAGE, requestMessage.getMessage()); return intent; }
/** Send the @a pathToImageFile back to the ImageModelImp's Handler via the @a Messenger. */ private void sendPath(Messenger messenger, Uri pathToImageFile, Uri url, int requestCode) { // Call the makeReplyMessage() factory method to create // Message. // TODO -x- you fill in here. RequestMessage requestMessage = RequestMessage.makeRequestMessage(requestCode, url, pathToImageFile, messenger); try { // Send the path to the image file back to the // ImageModelImpl's Handler via the Messenger. // TODO -x- you fill in here. requestMessage.getMessenger().send(requestMessage.getMessage()); } catch (RemoteException e) { Log.e(getClass().getName(), "Exception while sending reply message back to Activity.", e); } }