Android app Development

profilemainbox1
part2.zip

A2.pdf

Part 2

Threads

Purpose: The purpose of this assignment is to utilize a Threads to increase the performance on your application

1. Continue existing Todo project

2. Meet the following requirements

You app must fit the description that follows as well as meet the more specific list of

requirements. Your app must display an icon along with the todos/task information. The icon will be

provided by a library (.jar file). The library supplies 2 crucial methods. getImage(String id) that takes an id (previously supplied) and returns a Bitmap of an icon that is associated with that id. setImage(String id, int iconId) takes a String id and an int that is the icon id to associate with the string id. In order to get an image, you must first associate an id with an icon id by calling setImage. You may retrieve the list of all possible icon ids by calling getAvailableIds(). This returns a list of ints that are the available iconIds that you may use with setImage. You may also call getAvatars() that will return a list of Avatar objects that hold the id and image id of all the icons. You will need the last 2 methods to accomplish some of this task. (Important, the API ‘fails’ randomly about 20% of the time on purpose).

Your app must meet the following requirements:

1. All database operations must now be performed on a separate thread. 2. Your tasks list must display an image in its view. The image must be loaded from

the provided fake API, and be loaded asynchronously on a separate thread. 3. A progress spinner must be displayed while loading the task’s image from the

fake API 4. When creating a new Task, you must call setImage on the API to associate a

task with an icon.

Assignment Questions: (answer in a plain text file

1. Which methods on AsyncTask run in a background thread? Which run on the UI thread? 2. List the steps to create a Looper Thread? 3. Why is it important to run expensive tasks on a background thread? What are the

consequences of not running background threads for expensive operations? 4. What role does a Handler play in Android? 5. What are the drawbacks of using AsyncTask? What is the drawback of using regular

Java Threads?

ImageService/ImageService-1.0.jar

META-INF/MANIFEST.MF

Manifest-Version: 1.0

edu/towson/cosc431/valis/imageservice/ImageService.class

package edu.towson.cosc431.valis.imageservice;
public synchronized class ImageService {
    private static ImageService ourInstance;
    private static java.util.concurrent.ConcurrentHashMap map;
    private java.util.List data;
    private java.util.Random random;
    private java.util.List icons;
    public static ImageService getInstance();
    private void ImageService();
    public java.util.List getAvatars();
    public java.util.List getAvailableImageIds();
    public void setImage(String, int);
    public android.graphics.Bitmap getImage(String);
    static void <clinit>();
}

edu/towson/cosc431/valis/imageservice/Avatar.class

package edu.towson.cosc431.valis.imageservice;
public synchronized class Avatar {
    private String name;
    private int img;
    private int id;
    public void Avatar(String, int, int);
    public String getName();
    public void setName(String);
    public int getImg();
    public void setImg(int);
    public int getId();
}

edu/towson/cosc431/valis/imageservice/icon01.png

edu/towson/cosc431/valis/imageservice/icon02.png

edu/towson/cosc431/valis/imageservice/icon03.png

edu/towson/cosc431/valis/imageservice/icon04.png

edu/towson/cosc431/valis/imageservice/icon05.png