Good day everyone. I am writing an application for the site. The meaning is simple. From APi site in JSON format download all the materials. And then from the database we show the user. But the problem crept up from where I did not expect. When opening material with 1-10 pictures everything seems to be normal. But there are materials where there are a lot of images. It happens more than 50. And at this stage the application is closed due to a lack of device memory. Below is the Activity code in which the display should occur.
public class FullTextActivity extends ActionBarActivity implements Html.ImageGetter { TextView tv; WebView ww; TextView content; private final static String TAG = "TestImageGetter"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_full_text); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); tv = (TextView)findViewById(R.id.title); tv.setText(getIntent().getStringExtra("title")); Spanned spanned = Html.fromHtml(getIntent().getStringExtra("content"), this, null); tv = (TextView) findViewById(R.id.content); tv.setText(spanned); } @Override public Drawable getDrawable(String source) { LevelListDrawable d = new LevelListDrawable(); Drawable empty = getResources().getDrawable(R.drawable.ic_launcher); d.addLevel(0, 0, empty); d.setBounds(0, 0, empty.getIntrinsicWidth(), empty.getIntrinsicHeight()); new LoadImage().execute(source, d); return d; } class LoadImage extends AsyncTask<Object, Void, Bitmap> { private LevelListDrawable mDrawable; @Override protected Bitmap doInBackground(Object... params) { String sourceT = (String) params[0]; String source = sourceT.replace("../..", "http://mediananny.com"); mDrawable = (LevelListDrawable) params[1]; Log.d(TAG, "doInBackground " + source); try { InputStream is = new URL(source).openStream(); return BitmapFactory.decodeStream(is); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Bitmap bitmap) { Log.d(TAG, "onPostExecute drawable " + mDrawable); Log.d(TAG, "onPostExecute bitmap " + bitmap); if (bitmap != null) { BitmapDrawable d = new BitmapDrawable(bitmap); mDrawable.addLevel(1, 1, d); mDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight()); mDrawable.setLevel(1); // i don't know yet a better way to refresh TextView // mTv.invalidate() doesn't work as expected CharSequence t = tv.getText(); tv.setText(t); } } } }
To understand all the depths of the tragedy I show what exactly should be displayed in the application http://mediananny.com/reportazhi/2309660/
and here is what I have from the API http://mediananny.com/api/category/?offset=0&category_id=83&debug=true