Threaded Download Demo (Assignment 3)

Overview

The purpose of this assignment is to give you experience using various Android concurrency models to download bitmap images from a web server. The application works as follows:

Note that the results will look somewhat different if you use the AVD emulator vs. using a real Android smartphone shown in the screenshots above.


Program Description

This assignment involves writing an Android program that has the following features:

The entire layout of the application must be structured by the contents of the Android resource files described via XML, i.e., you must not hard-code any TextView, EditText, or Button objects into your ThreadedDownloadActivity class.


Skeleton Code

The following code is intended to give you some ideas of how to structure your program based on the solution I wrote. Feel free to change this skeleton code if you have a better solution.

package examples.threadeddownloads;

import android.app.Activity;
import android.os.AsyncTask;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import android.app.ProgressDialog;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import android.widget.ProgressBar;
import android.util.Log;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class ThreadedDownloadActivity extends Activity {
    // ... you fill in here

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // ... you fill in here
    }

    Bitmap downloadBitmap (String url) {
        // ... you fill in here
    }

    public void runRunnable(View view) {
        // ... you fill in here
    }

    public void runMessages(View view) {
        // ... you fill in here
    }

    public void runAsyncTask(View view) {
        // ... you fill in here
    }

    public void resetImage(View view) {
        // ... you fill in here
    }
}


Concluding Remarks

This programming assignment is more complicated than the first one. There's a great deal of useful information on Android concurrency models and HTTP client programming available on the web.


Back to CS 282 home page.