I was trying to retrieve images from internet and found similar samples then slightly changed the code I have found .But when I run my code I got this exception android.os.NetworkOnMainThreadException
.Then I have searched for solutions and noticed that I should use Asyntask
class for doing this.The problem is simple I just couldn't I get syntax errors at every line of code.Could you please help how to fix this code and make it run properly.Thanks in advance
class BackroundActivity extends AsyncTask<Void, Bitmap, Void>
{
@Override
protected Bitmap doInBackground(String src) throws IOException {
HttpURLConnection con = null;
URL url=new URL(src);
con=(HttpURLConnection) url.openConnection();
con.setDoInput(true);
InputStream input=con.getInputStream();
Bitmap bmp=BitmapFactory.decodeStream(input);
return bmp;
}