How to reduce the memory consumption of the application?

3d985f64478344cab7affa7a7783911e.jpg

Use Jsoup to parse the news and deduce them using ListView (view news: ImageView + TextView), but I began to notice that my app eats too much memory (seen from the screenshot above) with his harmless weight (1.9 MB). Help to find and eliminate the cause. The fault is in the library jsoup?

PS: for displaying images from network use the library Picasso.
September 19th 19 at 12:29
1 answer
September 19th 19 at 12:31
O Holy unicorns, how do you imagine the help of ordinary mortals who have no super powers to find out what you have there???
Application weight and less than 1 MB can on his knees to put the phone, so not the size of the case, and the code that you write and which is not here, to somehow to help you.
public class NewThread extends AsyncTask<string, void, arraylist<string>> {

@Override
 protected ArrayList<string> doInBackground(String... arg) {

 Document doc;
 urlIncomplete = "http://miped.ru/page/";
 url = urlIncomplete + pageNum;

 try {
 doc = Jsoup.connect(url).get();
imageList.clear();
titleList.clear();
linkList.clear();
 image = doc.select("div.story div.story_c img");
 title = doc.select("div.story div.story_title a");
 link = doc.select("div.story div.story_title a");
 for (Element images : image) {
imageList.add(images.attr("src"));
}
 for (Element titles : title) {
titleList.add(titles.text());
}
 for (Element links : link) {
linkList.add(links.attr("href"));
}
 } catch (IOException e) {
e.printStackTrace();
}
 return null;
}

@Override
 protected void onPostExecute(ArrayList<string> result) {
 if (pageNum != 1) {
prevPage.setVisibility(View.VISIBLE);
 } else {
prevPage.setVisibility(View.GONE);
}

news.setAdapter(adapter);

 news.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
 public void onItemClick(AdapterView<?> parent, View itemClicked, int position,
 long id) {
 int idClicked;
 idClicked = position;
 BrowseIntent Intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkList.get(idClicked)));
 browseIntent.putExtra("title", titleList.get(idClicked));
startActivity(browseIntent);
}
});

 news.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
 public boolean onItemLongClick(AdapterView<?> parent, View itemClicked, int position,
 long id) {
 int idClicked;
 idClicked = position;
@SuppressWarnings("deprecation")
 Copylink ClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
 copylink.setText(titleList.get(idClicked) + ": "+ linkList.get(idClicked));
 copy = Toast.makeText(getApplication(), R. string.copy
Toast.LENGTH_SHORT);
copy.show();
 return true;
}
});
}
 }</string></string></string>
- Fletcher_Abernathy commented on September 19th 19 at 12:34
news.setAdapter(adapter); - interested in how the adapter is implemented. Rather, the problem in it.
next code:
copy = Toast.makeText(getApplication(), R. string.copy
Toast.LENGTH_SHORT);
copy.show();
why did you create the variable???
Toast.makeText(getApplication(), R. string.copy, Toast.LENGTH_SHORT).show(); - Jean.Wilderman commented on September 19th 19 at 12:37
and missed:
int idClicked;
idClicked = position;
also:
idClicked int = position; - Jean.Wilderman commented on September 19th 19 at 12:40
: ordinary adapter, ImageView + TextView. - Fletcher_Abernathy commented on September 19th 19 at 12:43
Adapter class?
Throw the adapter code (unless you still need help). - Jean.Wilderman commented on September 19th 19 at 12:46
:
package ru.sezex.miped.adapter;

import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import ru.sezex.miped.R;

public class NewsAdapter extends BaseAdapter {
 ActionBarActivity context;
 public ArrayList<string> image;
 public ArrayList<string> title;

 public NewsAdapter(ActionBarActivity context,
 ArrayList<string> image,
 ArrayList<string> title) {
super();
 this.context = context;
 this.image = image;
 this.title = title;
}

 public int getCount() {
 return title.size();
}

 public Object getItem(int position) {
 return null;
}

 public long getItemId(int position) {
 return 0;
}

 private class ViewHolder {
 ImgViewPreview ImageView;
 TxtViewTitle TextView;
}

 public View getView(int position, View convertView, ViewGroup parent) {
 ViewHolder holder;
 if (convertView == null) {
 convertView = LayoutInflater.from(context).inflate(R. layout.main_item, parent, false);
 holder = new ViewHolder();
 holder.imgViewPreview = (ImageView) convertView.findViewById(R. id.preview);
 holder.txtViewTitle = (TextView) convertView.findViewById(R. id.title);
convertView.setTag(holder);
 } else {
 holder = (ViewHolder) convertView.getTag();
}

Picasso.with(context).load(image.get(position)).into(holder.imgViewPreview);
holder.txtViewTitle.setText(title.get(position));
 return convertView;
}
}</string></string></string></string>
- Fletcher_Abernathy commented on September 19th 19 at 12:49
Sorry for the long wait.
See official documentation from Picasso:

Place Holders
Picasso supports both download and error placeholders as optional features.
Picasso.with(context)
.load(url)
.placeholder(R. drawable.user_placeholder)
.error(R. drawable.user_placeholder_error)
.into(imageView);

Next:

Image Transformations
Transform images to better fit into layouts and to reduce memory size.
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView) - Jean.Wilderman commented on September 19th 19 at 12:52
: what do you mean? Pictures are displayed without additional parameters. - Fletcher_Abernathy commented on September 19th 19 at 12:55
Naturally displayed without additional parameters. What sizes of images you load into memory? And what is the size of the displayed imgViewPreview? Picasso without additional parameters (i.e. without optimization) keeps the cache and memory devices in RAM. You're parsite news list and images take from the same place? - Jean.Wilderman commented on September 19th 19 at 12:58
: image - 450x300, ImageView - parent/150dp. - Fletcher_Abernathy commented on September 19th 19 at 13:01
Just try for example, Picasso..resize(50, 50)
Graphics compare memory consumption - Jean.Wilderman commented on September 19th 19 at 13:04

Find more questions by tags Android