相关疑难解决方法(0)

使用AsyncTask加载位图图像

我试图通过我的应用程序在后台加载图像.我写的逻辑是这样的:

public class ImageLoader extends AsyncTask <Context, Void, Bitmap>{

    private String URL;
    private int type;

    ImageLoader(String Url, int Type)
    {
        URL = Url;
        type = Type;
    }

    @Override
    protected Bitmap doInBackground(Context... arg0) {

        AssetManager assetMgr = arg0[0].getAssets();
        Bitmap bitmap = null;
        try {
            bitmap = BitmapFactory.decodeStream(assetMgr.open(URL));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bitmap;
    }

    @Override
    protected void onPostExecute( Bitmap result )  {
          super.onPostExecute(result);

          if (type == 1)
              Inst1 = result;
          else if (type == 2)
              Inst2 = result; …
Run Code Online (Sandbox Code Playgroud)

java android loader android-asynctask

2
推荐指数
1
解决办法
8972
查看次数

标签 统计

android ×1

android-asynctask ×1

java ×1

loader ×1