![]() |
![]() |
![]() |
![]() |
<uses-permission
android:name="android.permission.INTERNET">
</uses-permission>
ThreadedDownloadActivity
class that
inherits from Activity
and uses the XML layout containing
a TextView
object that prompts for the URL of the bitmap
file and stores the entered URL in an EditText
object.
Button
objects with the label "Run
Runnable", "Run Messages", "Run Async", and "Reset Image" to run the
corresponding hook methods that use the URL provided by the user to
download the designated bitmap file via one of the following three
Android concurrency models:
Button
objects that download the bitmap file
must be connected to the corresponding
ThreadedDownloadActivity.run*()
methods via the
appropriate android:onClick="..."
attributes.
TextView
,
EditText
, or Button
objects into your
ThreadedDownloadActivity
class.
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
}
}
Back to CS 282 home page.