Note that there are some explanatory texts on larger screens.

plurals
  1. POOn Click Of Tabs(Radio Button) My Memory Getting Double
    primarykey
    data
    text
    <p>My layout is very complex. I have to make full page scrollable so what i did is - i have a gridView adapter for my gridview items and one custom adapter which has four tabs and then i set my gridview in that custom adapter. Then this whole view is set on my main activity which has a listview so its now scrolling with full page but issue is with memory.</p> <p>I have 4 tab click events on custom adapter from which i am sending those click events through put extra to main activity where i have four web service and a condition that if 1st tab is selected then 1st web service call will occur and new adapter will set on main activity.</p> <p><strong>problem</strong>: when i click on 1st tab my memory size is 130 MB and on click of 2nd tab it raises to double so and same thing is happen when i click on 3rd tab. I am using lazy loading for loading my images which also maintains my caching, i have tried clear(), notifyDataSetChanged() but doesn't make any change. My memory is increasing on each click of tabs. </p> <p>Here is my code:</p> <p><strong>GallaryLoginMainActivity</strong>:</p> <pre><code> public class GallaryLoginMainActivity&lt;T&gt; extends BaseClass { /** * Description:Declare the UI components. */ private List&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; data = null; private ListView lstGallaryMain = null; public ArrayList&lt;HashMap&lt;String, String&gt;&gt; userDataActivity; public ArrayList&lt;HashMap&lt;String, String&gt;&gt; userDataSecondActivity; private ProgressDialog loadingDialog = null; LinkedHashMap&lt;String, String&gt; linkedMap; ArrayList&lt;Assignment&gt; assignmentArrayList; private String selectedTab = "popular"; private ImageLoader imageloader; // public static ArrayAdapter mAdapter; public ArrayAdapter mAdapter; /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetFiles() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap&lt;String, String&gt;(); gsp.parseXML(restService.getResponse()); // userDataActivity = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); userDataActivity = gsp.userData; System.out.println("RR : userDataActivity from LoginMainAct :" + userDataActivity.size()); System.out.println("RR : from userdataactivty for item:" + userDataActivity.get(0).toString()); data.add(userDataActivity); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetFilesInfo() { // new Thread(new Runnable() { // public void run() { GallerySaxParserForGetFileInfo gisp = new GallerySaxParserForGetFileInfo(); try { RestService restService = new RestService(); linkedMap = new LinkedHashMap&lt;String, String&gt;(); System.out.println("From GallaryUserLoginMainActivity1 : " + restService.getResponse()); gisp.parseXML(restService.getResponse()); userDataSecondActivity = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); userDataSecondActivity = gisp.userSecondData; data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } // } // }).start(); } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByPopuler() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap&lt;String, String&gt;(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); // }; // }.execute(); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByRecent() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap&lt;String, String&gt;(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByComment() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap&lt;String, String&gt;(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } } /** * Description:This method use for prepare the request to get the response * from API * */ public void MediaGetShortedFilesByNearBy() { final GallerySaxParserForGetFiles gsp = new GallerySaxParserForGetFiles(); final RestService restService = new RestService(); try { linkedMap = new LinkedHashMap&lt;String, String&gt;(); gsp.parseXML(restService.getResponse()); userDataActivity = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); userDataActivity = gsp.userData; data.add(userDataActivity); data.add(userDataSecondActivity); } catch (Exception e) { e.printStackTrace(); } } /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallary_login_main_page_list); init(GallaryLoginMainActivity.this, R.id.main, getIntent()); data = new ArrayList&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt;(); imageloader = new ImageLoader(getApplicationContext()); Intent intent = getIntent(); if (intent.getExtras().getString("SELECTED_TAB") != null) { selectedTab = intent.getExtras().getString("SELECTED_TAB"); } /* * * This method is used to Show The loading dialog till the data * loads for main page. */ new AsyncTask&lt;Void, Void, Void&gt;() { protected void onPreExecute() { loadingDialog = ProgressDialog.show(GallaryLoginMainActivity.this, "", "Loading. Please wait...", true); } @Override protected Void doInBackground(Void... params) { return null; }; protected void onPostExecute(Void result) { if (selectedTab.equalsIgnoreCase("popular")) { MediaGetShortedFilesByPopuler(); } else if (selectedTab.equalsIgnoreCase("recent")) { MediaGetShortedFilesByRecent(); } else if (selectedTab.equalsIgnoreCase("commented")) { MediaGetShortedFilesByComment(); } if (mAdapter != null) { mAdapter = null; mAdapter.clear(); } if (mAdapter == null) { lstGallaryMain = (ListView) findViewById(R.id.lstGallaryMain); mAdapter = new GalleryCustomAdapterForMainPage&lt;T&gt;(GallaryLoginMainActivity.this, data); // mAdapter.notifyDataSetChanged(); } lstGallaryMain.setAdapter(mAdapter); if (loadingDialog != null &amp;&amp; loadingDialog.isShowing()) { loadingDialog.dismiss(); } }; }.execute(); } } @Override protected void onResume() { System.gc(); super.onResume(); } @Override protected void onPause() { super.onPause(); System.gc(); } @Override public void onLowMemory() { super.onLowMemory(); imageloader.clearCache(); } @Override protected void onDestroy() { lstGallaryMain.setAdapter(null); userDataActivity = null; userDataSecondActivity = null; System.gc(); super.onDestroy(); } } </code></pre> <p><strong>GalleryCustomAdapterForMainPage</strong>:</p> <pre><code> public class GalleryCustomAdapterForMainPage&lt;T&gt; extends ArrayAdapter&lt;T&gt; { public static int gridviewHeight = 0; private GridView refGridView; /** * Description:Declare the UI components. */ List&lt;ArrayList&lt;HashMap&lt;String, String&gt;&gt;&gt; data = null; public ArrayList&lt;HashMap&lt;String, String&gt;&gt; userDataActivity; public ArrayList&lt;HashMap&lt;String, String&gt;&gt; userDataSecondActivity; private ProgressDialog loadingDialog = null; // AQuery listAQ; private Activity mContext = null; private LayoutInflater inflater = null; Bitmap galleryBitmapHadnling = null; private PopupWindow mpopup; LinkedHashMap&lt;String, String&gt; linkedMap; Holder1 h1; GalleryMainActivityGridViewAdapter gmaga = null; private ImageLoader imageloader; /** * This method is use to set object that will control the listview * * @param activity * that creates this thing * @param data * bind to this listview */ // This Class is used to Declare a CustomAdapter that we use to join the // data set and the ListView public GalleryCustomAdapterForMainPage(Activity activity, List data) { super(activity, R.layout.gallery_main_page_content, data); this.mContext = activity; // listAQ = new AQuery(mContext); this.data = data; this.userDataActivity = this.data.get(0); System.out.println("userDataActivity is : " + userDataActivity); this.userDataSecondActivity = this.data.get(1); // listAQ = new AQuery(mContext); // Get a new instance of the layout view inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageloader = new ImageLoader(mContext); } // Total number of things contained within the adapter @Override public int getCount() { return this.data.size() - 1; } // create View for each item referenced by the Adapter @SuppressWarnings("deprecation") @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { /* create a new view of our layout and inflate it in the row */ // Inflate the layout convertView = inflater.inflate(R.layout.gallery_main_page_content, null); // System.gc(); h1 = new Holder1(); // Initialize the UI components h1.imgView_Gallery_Main_Background = (ImageView) convertView.findViewById(R.id.imgView_Gallery_Main_Background); h1.txtView_main_img_title = (TextView) convertView.findViewById(R.id.txtView_main_img_title); Typeface typeForTitile = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_bold_neue.ttf"); h1.txtView_main_img_title.setTypeface(typeForTitile); h1.texView_featured = (TextView) convertView.findViewById(R.id.texView_featured); Typeface typeForFeatured = Typeface.createFromAsset(getContext().getAssets(), "fonts/gotham_black_1.ttf"); h1.texView_featured.setTypeface(typeForFeatured); h1.txtView_assignment_detail = (TextView) convertView.findViewById(R.id.txtView_assignment_detail); Typeface typeAssignmentDetail = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold_1.ttf"); h1.txtView_assignment_detail.setTypeface(typeAssignmentDetail); h1.imgView_Main_TumbNail = (ImageView) convertView.findViewById(R.id.imgView_Main_TumbNail); h1.txtView_gallery_main_person_name = (TextView) convertView.findViewById(R.id.txtView_gallery_main_person_name); Typeface txtViewPersonName = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.txtView_gallery_main_person_name.setTypeface(txtViewPersonName); h1.txtView_gallery_main_views = (TextView) convertView.findViewById(R.id.txtView_gallery_main_views); Typeface txtViewViews = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.txtView_gallery_main_views.setTypeface(txtViewViews); h1.texView_gallery_main_comment = (TextView) convertView.findViewById(R.id.texView_gallery_main_comment); Typeface txtViewComments = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.texView_gallery_main_comment.setTypeface(txtViewComments); h1.texView_gallery_main_favorite = (TextView) convertView.findViewById(R.id.texView_gallery_main_favorite); Typeface txtViewFavorite = Typeface.createFromAsset(getContext().getAssets(), "fonts/arial_bold.ttf"); h1.texView_gallery_main_favorite.setTypeface(txtViewFavorite); h1.btn_Gallery_Main_ShowMe = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Main_ShowMe); h1.btn_Gallery_Tab_Popular = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_Popular); Typeface TabPopular = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.btn_Gallery_Tab_Popular.setTypeface(TabPopular); h1.btn_Gallery_Tab_Popular.setChecked(true); h1.btn_Gallery_Tab_recent = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_recent); Typeface TabRecent = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.texView_gallery_main_favorite.setTypeface(TabRecent); h1.btn_Gallery_Tab_Commented = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_Commented); Typeface TabCommented = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.texView_gallery_main_favorite.setTypeface(TabCommented); h1.btn_Gallery_Tab_Nearby = (RadioButton) convertView.findViewById(R.id.btn_Gallery_Tab_Nearby); Typeface TabNearby = Typeface.createFromAsset(getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); h1.texView_gallery_main_favorite.setTypeface(TabNearby); h1.imgView_ForPlayVideo = (ImageView) convertView.findViewById(R.id.imgView_ForPlayVideo); if (userDataActivity.get(position).get("filetype").toString().endsWith("1")) { h1.imgView_ForPlayVideo.setVisibility(View.GONE); } else { h1.imgView_ForPlayVideo.setVisibility(View.VISIBLE); } // set the content in grid view of gallery main page h1.gridview_Gallery = (GridView) convertView.findViewById(R.id.gridview_Gallery); int gridHeight = (int) ((userDataActivity.size() / 3) * 140 * 1.80); System.out.println("gridHeigh is : " + gridHeight); if (h1.btn_Gallery_Tab_Popular != null) { h1.txtView_gallery_main_person_name.setText(" " + userDataActivity.get(position).get("user_name")); h1.txtView_main_img_title.setText(userDataActivity.get(position).get("title")); h1.txtView_gallery_main_views.setText(" | " + userDataActivity.get(position).get("hits") + " views"); h1.texView_gallery_main_comment.setText(" | " + userDataActivity.get(position).get("commentcount") + " "); h1.texView_gallery_main_favorite.setText(" | " + userDataActivity.get(position).get("votecount") + " "); imageloader.DisplayImage(userDataActivity.get(position).get("thumbUrl") + "/12", h1.imgView_Gallery_Main_Background); // h1.imgView_Main_TumbNail.setImageBitmap(getBitmap(userDataActivity.get(position).get("thumbUrl") // + "/12")); if (userDataActivity.get(position).get("publicUrl") != null) { imageloader.DisplayImage(userDataActivity.get(position).get("publicUrl") + "/14", h1.imgView_Gallery_Main_Background); } else { h1.imgView_Gallery_Main_Background.setBackgroundResource(R.drawable.loading); } } userDataActivity.remove(0); if (h1.gridview_Gallery != null) { // clearAdapter(); // setting the adapter // if (gmaga == null) { gmaga = new GalleryMainActivityGridViewAdapter(mContext, userDataActivity); // } h1.gridview_Gallery.setAdapter(gmaga); // Total number of things contained within the adapter int gridHeight1 = (int) ((h1.gridview_Gallery.getAdapter().getCount() / 3) * 120 * 1.80); h1.gridview_Gallery.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, gridHeight1)); h1.gridview_Gallery.setSelector(new ColorDrawable(color.transparent)); h1.gridview_Gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { Intent intent = new Intent(mContext, GalleryDetailPageActivity.class); System.out.println("pos:" + userDataActivity.get(position).get("id")); // This will send the items via intent to Gallery detail // page to display data on that page. intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); } }); } if (h1.btn_Gallery_Tab_Popular != null) { h1.btn_Gallery_Tab_Popular.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(mContext, GallaryLoginMainActivity.class); intent.putExtra("SELECTED_TAB", "popular"); intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); mContext.finish(); // } } }); } if (h1.btn_Gallery_Tab_recent != null) { h1.btn_Gallery_Tab_recent.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, GallaryLoginMainActivity.class); intent.putExtra("SELECTED_TAB", "recent"); intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); mContext.finish(); // } } }); } if (h1.btn_Gallery_Tab_Commented != null) { h1.btn_Gallery_Tab_Commented.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, GallaryLoginMainActivity.class); intent.putExtra("SELECTED_TAB", "commented"); intent.putExtra("tabId", R.id.tab_b01); intent.putExtra("tabBackgroundId", R.drawable.tab_b01_on); mContext.startActivity(intent); mContext.finish(); // } } }); } convertView.setTag(h1); } return convertView; } private class Holder1 { ImageView imgView_Gallery_Main_Background; TextView txtView_main_img_title; TextView texView_featured; RadioButton btn_Gallery_Tab_Popular; RadioButton btn_Gallery_Tab_recent; RadioButton btn_Gallery_Tab_Commented; RadioButton btn_Gallery_Tab_Nearby; ImageView imgView_Main_TumbNail; TextView txtView_assignment_detail; TextView txtView_assignment_name; TextView txtView_gallery_main_person_name; TextView txtView_gallery_main_views; TextView texView_gallery_main_comment; TextView texView_gallery_main_favorite; RadioButton btn_Gallery_Main_ShowMe; GridView gridview_Gallery; ImageView imgView_ForPlayVideo; } } </code></pre> <p><strong>GalleryMainActivityGridViewAdapter</strong>:</p> <pre><code>public class GalleryMainActivityGridViewAdapter extends BaseAdapter { // AQuery listAQ; private Context mContext; int layoutResourceId; ArrayList&lt;HashMap&lt;String, String&gt;&gt; dataArray; ArrayList&lt;Boolean&gt; selected; private GallerySmartLazyLoader lazyloader; private ImageLoader imageloder; public static String dataExtension = " Views"; public GalleryMainActivityGridViewAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; resultArray) { this.mContext = context; // this.layoutResourceId = layoutId; this.dataArray = resultArray; // listAQ = new AQuery(mContext); lazyloader = new GallerySmartLazyLoader(mContext); imageloder = new ImageLoader(mContext.getApplicationContext()); // aa = new ArrayAdapter&lt;Photo&gt;(mContext, layoutResourceId); } public int getCount() { return dataArray.size(); } public void clear() { dataArray.clear(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } // BitmapFactory.Options options = null; // Bitmap cachedImage; @SuppressWarnings("deprecation") public View getView(int position, View convertView, ViewGroup parent) { String url = null; GalleryHolder holder = null; if (convertView == null) { convertView = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.gallery_main_page_grid_item, parent, false); convertView.setTag(holder); } else { holder = (GalleryHolder) convertView.getTag(); } holder = new GalleryHolder(); try { String thumbnail = dataArray.get(position).get("thumbUrl") + "/11"; holder.imgView_Grid_Thumbnail_Gallery = (ImageView) convertView.findViewById(R.id.imgView_Grid_Thumbnail_Gallery); if (holder.imgView_Grid_Thumbnail_Gallery != null) { } } catch (Exception e) { e.printStackTrace(); } holder.txtView_Grid_Name_Gallery = (TextView) convertView.findViewById(R.id.txtView_Grid_Name_Gallery); Typeface TabGridname = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); holder.txtView_Grid_Name_Gallery.setTypeface(TabGridname); if (holder.txtView_Grid_Name_Gallery != null) { // holder.txtView_Grid_Name_Gallery.getId()).text(dataArray.get(position).get("user_name")); holder.txtView_Grid_Name_Gallery.setText(dataArray.get(position).get("user_name")); Typeface txtViewForName = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); holder.txtView_Grid_Name_Gallery.setTypeface(txtViewForName); } ImageView v = holder.imgView_GridItem_Gallery = (ImageView) convertView.findViewById(R.id.imgView_GridItem_Gallery); if (holder.imgView_GridItem_Gallery != null) { String publicUrl = dataArray.get(position).get("publicUrl") + "/14"; imageloder.DisplayImage(publicUrl, holder.imgView_GridItem_Gallery); } holder.txtView_Grid_Views_Gallery = (TextView) convertView.findViewById(R.id.txtView_Grid_Views_Gallery); Typeface TabGriddetail = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/helvetica_ce_regular.ttf"); holder.txtView_Grid_Name_Gallery.setTypeface(TabGriddetail); if (holder.txtView_Grid_Views_Gallery != null) { if (isPopuler) { holder.txtView_Grid_Views_Gallery.setText(dataArray.get(position).get("hits") + dataExtension); } else if (isUpload) { GalleryMainActivityGridViewAdapter.dataExtension = dataArray.get(position).get("upload"); holder.txtView_Grid_Views_Gallery.setText(dataArray.get(position).get("upload")); } else if (isComments) { holder.txtView_Grid_Views_Gallery.setText(dataArray.get(position).get("commentcount") + dataExtension); } // else if (isNearby) { // aq.id(holder.txtView_Grid_Views_Gallery.getId()).text(dataArray.get(position).get("commentcount") // + dataExtension); // } Typeface txtViewForViews = Typeface.createFromAsset(convertView.getContext().getAssets(), "fonts/arial_bold.ttf"); holder.txtView_Grid_Views_Gallery.setTypeface(txtViewForViews); } holder.imgView_Grid_PlayVideo = (ImageView) convertView.findViewById(R.id.imgView_Grid_PlayVideo); if (holder.imgView_Grid_PlayVideo != null) { if (dataArray.get(position).get("filetype").toString().equals("1")) { holder.imgView_Grid_PlayVideo.setVisibility(View.GONE); } else { holder.imgView_Grid_PlayVideo.setVisibility(View.VISIBLE); } } return convertView; } class GalleryHolder { ImageView imgView_Grid_PlayVideo; ImageView imgView_Grid_Thumbnail_Gallery; TextView txtView_Grid_Views_Gallery; TextView txtView_Grid_Name_Gallery; ImageView imgView_GridItem_Gallery; } } </code></pre> <p><strong>pic</strong></p> <p><img src="https://i.stack.imgur.com/74muf.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload