Created
April 24, 2014 09:13
-
-
Save kikuchy/11247663 to your computer and use it in GitHub Desktop.
AsyncTaskLoaderを使った画像の読み込みクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jnet.kikuchy; | |
import android.support.v4.content.AsyncTaskLoader; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.util.Log; | |
import java.io.InputStream; | |
import java.net.URL; | |
public class ImageAsyncLoader extends AsyncTaskLoader<Bitmap> { | |
private static final String TAG = MainActivity.class.getSimpleName(); | |
private String mUrl; | |
public ImageAsyncLoader(Context context, String url) | |
{ | |
super(context); | |
this.mUrl = url; | |
} | |
@Override | |
public Bitmap loadInBackground() { | |
Bitmap ret = null; | |
try { | |
URL url = new URL(this.mUrl); | |
InputStream input = url.openStream(); | |
ret = BitmapFactory.decodeStream(input); | |
} | |
catch (Exception e) | |
{ | |
Log.e(TAG, e.getMessage()); | |
} | |
return ret; | |
} | |
@Override | |
public void onStartLoading() { | |
forceLoad(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment