Hello! I need your help.
I am writing an application on Android, where a link to a text file with links to forum pages is parsed using jsoup. The file and links in it are periodically updated by me from the outside.
class ParseMyPageTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { try { input = new URL("https://gist.githubusercontent.com/akhorevich/5b849373dc9abaf921b3/raw/18e79ab6a0c0be007a2a4590e4e176184ced311a/links"); sc = new Scanner(input.openStream()); while(sc.hasNextLine()){ String link = sc.nextLine(); doc = Jsoup.connect(link).get(); Elements names = doc.select("div.node-title"); // Elements images = doc.select("div.node div.content img"); Elements imgs = doc.select("div.node div.content img"); for (Element img : imgs) { Element myImage = img; String imgSrc = myImage.attr("src"); InputStream inp = new java.net.URL(imgSrc).openStream(); // Decode Bitmap bitmap = BitmapFactory.decodeStream(inp); allImages.add(bitmap); } for(Element name: names) { mData.add(name.text()); } if(mData.size() == 0) { mData.add("Empty result"); } } } catch (IOException e) { e.printStackTrace(); mData.clear(); mData.add("Exception: " + e.toString()); } return text; // получаем весь текст } @Override protected void onPostExecute(String result) { super.onPostExecute(result); sectorC_adapter = new SectorC_Adapter(getActivity()); mListView.setAdapter(sectorC_adapter); } } class SectorC_Adapter extends BaseAdapter{ private Context c; SectorC_Adapter(Context c){ this.c = c; } @Override public int getCount() { return mData.size(); } @Override public Object getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView==null){ inflater = (LayoutInflater)c .getSystemService(c.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.sector_row, parent,false); }else { row = convertView; } tvInfo = (TextView)row.findViewById(R.id.dog_name); tvInfo.setText(mData.get(position).toString()); dog_view = (ImageView)row.findViewById(R.id.dog_view); dog_view.setImageBitmap(allImages.get(position)); return row; } } Something like this all looks like. But there are two problems -
Pictures are parsed only from the first link in the file (I specifically have dogs - let's say different pictures of Bugs are inserted into all the elements, but it’s necessary that each link has its own photo of the dog)
The second problem is that it eats too much memory and the application periodically crashes. Is it possible to load photos into the buffer or onto a map or somewhere else, and then upload?
Thank you very much!