package com.da.lon.wang.xlg.activity;import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;import com.appkefu.lib.interfaces.KFAPIs;
import com.bumptech.glide.Glide;
import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.CartNubBean;
import com.da.lon.wang.xlg.bean.DetailBean;
import com.da.lon.wang.xlg.bean.DetailBean.NomeList.Value;
import com.da.lon.wang.xlg.bean.DetailListBean;
import com.da.lon.wang.xlg.bean.IdsBean;
import com.da.lon.wang.xlg.bean.OrderListBean;
import com.da.lon.wang.xlg.bean.ZanBean;
import com.da.lon.wang.xlg.constants.PreferencesConfig;
import com.da.lon.wang.xlg.fragment.OneFragment;
import com.da.lon.wang.xlg.fragment.ThreeFragment;
import com.da.lon.wang.xlg.fragment.TwoFragment;
import com.da.lon.wang.xlg.http.HttpLoader;
import com.da.lon.wang.xlg.http.HttpLoader.OnWebLoadListener;
import com.da.lon.wang.xlg.util.BuyUtil;
import com.da.lon.wang.xlg.util.DialogUtil;
import com.da.lon.wang.xlg.util.PreferenceUtils;
import com.da.lon.wang.xlg.util.SingleManager;
import com.da.lon.wang.xlg.util.XLGDataUtils;
import com.da.lon.wang.xlg.view.CancelPopWindow;
import com.da.lon.wang.xlg.view.McoyProductContentPage;
import com.da.lon.wang.xlg.view.McoyProductDetailInfoPage;
import com.da.lon.wang.xlg.view.McoySnapPageLayout;
import com.da.lon.wang.xlg.view.MyViewPager;
import com.da.lon.wang.xlg.view.ProductsPopupWindow;
import com.da.lon.wang.xlg.view.QuestionPopupWindow;
import com.jauker.widget.BadgeView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.squareup.picasso.Picasso;
import com.umeng.analytics.MobclickAgent;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.tsz.afinal.http.AjaxParams;public class ProductsActivity extends BaseActivity implements OnClickListener { private HttpLoader<DetailListBean> loader;
private HttpLoader<OrderListBean> loader3;
private DetailBean bean = new DetailBean();
// private ImageLoader loader2;
private HttpLoader<ZanBean> loader4;
private HttpLoader<CartNubBean> loader5;
private HttpLoader<IdsBean> loader6; private McoySnapPageLayout mcoySnapPageLayout = null;
private McoyProductContentPage bottomPage = null;
private McoyProductDetailInfoPage topPage = null; private LinearLayout popupwindowLayout;
private ProductsPopupWindow contentWindow;
private QuestionPopupWindow questionWindow;
private CancelPopWindow cancelPopWindow;
private Button bottomLayout; private View view;
private Context context; private String product_number; private List<Fragment> fragmentList;
private MyViewPager detailPager;
private TextView detailView1, detailView2, detailView3; private ImageView img_line;
private int screenWidth;
private int currenttab = 0; private MyViewPager pager;
private ImageView[] tips;
private TextView nameView;
private Button buyButton; private LinearLayout topLayout; private ImageButton backButton, smileButton, ringButton, shareButton; private TextView collectBox;
private TextView cartView;
private Button addcartButton; // 滑动条颜色
private int select_color;
private int unselect_color; private int mScreen1_4; /** 当前视图宽度 **/
private Integer viewPagerW = 0; private static int width = 0; private OneFragment oneFragment;
private TwoFragment twoFragment;
private ThreeFragment threeFragment;
private DialogUtil dialogUtil;
String user_id = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.USER_ID, "");
String device_id = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.DEVICE_ID, ""); private String ids;
private ImageView imageView;
private boolean BackState =false;
private ArrayList<Fragment> arrayList;
public int index =1;
private FragmentTransaction ft; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState); setContentView(R.layout.ouka_products_main);
buyButton = (Button) findViewById(R.id.ouka_products_bottom);
backButton = (ImageButton) findViewById(R.id.detail_back);
smileButton = (ImageButton) findViewById(R.id.detail_smile);
ringButton = (ImageButton) findViewById(R.id.detail_ring);
shareButton = (ImageButton) findViewById(R.id.detail_share); collectBox = (TextView) findViewById(R.id.ouka_products_collect);
cartView = (TextView) findViewById(R.id.ouka_products_cart);
addcartButton = (Button) findViewById(R.id.ouka_products_addcart); cartView.setOnClickListener(this);
addcartButton.setOnClickListener(this);
collectBox.setOnClickListener(this); buyButton.setOnClickListener(this);
backButton.setOnClickListener(this);
smileButton.setOnClickListener(this);
ringButton.setOnClickListener(this);
shareButton.setOnClickListener(this); topLayout = (LinearLayout) findViewById(R.id.detail_top);
topLayout.bringToFront(); context = this; PreferenceUtils.getInstance().SetSettingString(PreferencesConfig.COUNT_NUMBER, "1"); String is_collect = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.IS_COLLECT, ""); if (is_collect.equals("")) {
Drawable drawable = getResources().getDrawable(R.drawable.ocoffee_collect_normal);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
collectBox.setCompoundDrawables(null, drawable, null, null);
} else { if (is_collect.equals("1")) {
Drawable drawable = getResources().getDrawable(R.drawable.ocoffee_collect_pressed);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
collectBox.setCompoundDrawables(null, drawable, null, null);
} else {
Drawable drawable = getResources().getDrawable(R.drawable.ocoffee_collect_normal);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
collectBox.setCompoundDrawables(null, drawable, null, null);
}
}
dialogUtil = new DialogUtil(context);
initCart();
init(); } private void initCart() {
// TODO Auto-generated method stub loader5 = new HttpLoader<CartNubBean>(context, "http://api.ocoffee.cn/Cart-cartcount", CartNubBean.class,
60 * 1000);
AjaxParams params = new AjaxParams(); params.put("id", user_id);
params.put("deviceId", device_id);
params.put("token", XLGDataUtils.encrypt2MD5("Cart" + "2015#$%" + "cartcount")); loader5.setManagerListener(new OnWebLoadListener<CartNubBean>() { @Override
public void OnStart() {
// TODO Auto-generated method stub
dialogUtil.showDialog();
System.out.println("请求开始!"); } @Override
public void OnError(String error) {
// TODO Auto-generated method stub
dialogUtil.dismissDialog();
System.out.println("请求错误!" + error);
} @Override
public void onSuccess(CartNubBean t) {
// TODO Auto-generated method stub
dialogUtil.dismissDialog(); System.out.println("请求成功!"); if (t != null && t.getCode().equals("000000")) {
if (t.getResult().equals("0")) { } else {
BadgeView badgeView = new BadgeView(context);
badgeView.setTargetView(cartView);
badgeView.setBadgeCount(Integer.parseInt(t.getResult()));
}
}
}
}); loader5.loadData(params);
} @Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
} @Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);// Glide.clear(imageView);

// Glide.get(this).clearMemory(); // MyApplication.getWith().shutdown();
} @Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
dialogUtil.dismissDialog();
this.setContentView(R.layout.empty_ll);
loader =null;
loader3=null;
loader4 =null;
loader5=null;
loader6=null;
topPage=null;
bottomPage =null;
view=null;
arrayList =null;
// System.gc();
} private void init() {
// TODO Auto-generated method stub product_number = PreferenceUtils.getInstance().getSettingStr(PreferencesConfig.PRODUCT_NUMBER, ""); loader = new HttpLoader<DetailListBean>(context, "http://api.ocoffee.cn/Product-details", DetailListBean.class,
60 * 1000);
AjaxParams params = new AjaxParams(); params.put("product_number", product_number);
params.put("token", XLGDataUtils.encrypt2MD5("Product" + "2015#$%" + "details")); System.out.println("商品详情接口请求:" + params); loader.setManagerListener(new OnWebLoadListener<DetailListBean>() { @Override
public void OnStart() {
// TODO Auto-generated method stub
dialogUtil.showDialog();
System.out.println("请求开始!"); }

解决方案 »

  1.   

    你这是图片又多有大,导致加载时还没有显示就oom了,对图片进行一次压缩,优化一下,其他占用内存大的地方
      

  2.   

    最好把log发上来看一下,建议使用MAT工具分析下内存占用情况。
    涉及到加载drawable中图片导致oom的话,可以看下这个http://blog.csdn.net/chniccs/article/details/51373623
      

  3.   

    先把activity设置成singleTop不要每次启动都重新创建,看能否解决这个问题。当然这个方法治标不治本,根本的问题还是要MAT分析下看是什么地方内存泄漏的把所有的清理回收资源的地方都注销了是什么鬼?
    // Glide.clear(imageView);
    // Glide.get(this).clearMemory();
    // MyApplication.getWith().shutdown();
    // System.gc();
      

  4.   

    MobclickAgent
      

  5.   

    首先成员变量在Destroy时置null是没有任何作用的,垃圾回收正常情况一定会回收这些东西,无论你有没有置null。垃圾回收无法回收的情况:静态引用、无限handler、一些第三方sdk、网络请求一直等待不返回、application类强引用。新手博客常见问题3有具体描述:https://blog.csdn.net/weimingjue/article/details/87921494看你的成员变量里的东西,基本上是HttpLoader里面有问题,你贴一下这里的代码。还有写这么多成员变量不累吗,Destroy的时候setView不怕崩溃吗
      

  6.   

    还有命名、system.out等等就不多吐槽了