是不是activity2里面有些操作导致了 程序崩了 返回了activity1了?

解决方案 »

  1.   

    贴下代码看下呗,activity2怎么ondestory的
      

  2.   

    没有遇到过,, 自动  activity2自动销毁.. ?
      

  3.   

    是不是activity2损耗内存达到一定程度destroy,而你的activity1又没有finish()才有这种情况
      

  4.   

    package lht.inspection.activity;
    import java.util.ArrayList;
    import java.util.HashMap;import lht.inspection.model.Equipment;
    import lht.inspection.model.InspectionProject;
    import lht.inspection.overrideadapter.EquipmentActivityListviewAdapter;
    import lht.inspection.overrideitemclick.EquipmentActivityListviewItemClick;
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Looper;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.Window;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;public class EquipmentActivity extends Activity {
    public String ip;
    public String Url;
    public String port;
    public String user_real_name;
    public String user_id;
    public String djjhdh, djjhid;
    public ListView listview;
    public Button backButton;
    public TextView equipmenttextview;
    public ArrayList<Equipment> list;
    public HashMap<String, ArrayList<Equipment>> e_map;
    public HashMap<String, ArrayList<InspectionProject>> pro_map;
    private String[] parameters = new String[3];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO 自动生成的方法存根
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_equipment);
    ip = getResources().getString(R.string.ip).toString();
    port = getResources().getString(R.string.port);
    Url = "http://"+ ip +":" + port + "/WebService.asmx?wsdl";
    listview = (ListView)findViewById(R.id.equipmentlistview);
    backButton = (Button)findViewById(R.id.equipmentbutton);
    backButton.setOnClickListener(new BackButtonClickListener());
    Bundle bundle = getIntent().getExtras();
    user_real_name = bundle.getString("myname");
    user_id = bundle.getString("userid");
    //djjhdh = bundle.getString("djjhdh");
    djjhid = bundle.getString("djjhid");
    //parameters[0] = djjhdh;
    e_map = (HashMap<String, ArrayList<Equipment>>)getIntent().getSerializableExtra("e_map");
    pro_map = (HashMap<String, ArrayList<InspectionProject>>)getIntent().getSerializableExtra("pro_map"); list = e_map.get(djjhid);
    if(list != null && list.size() > 0){
    EquipmentActivityListviewAdapter listAdapter = new EquipmentActivityListviewAdapter(EquipmentActivity.this, list);
    listview.setAdapter(listAdapter);
    EquipmentActivityListviewItemClick itemclick = new EquipmentActivityListviewItemClick(EquipmentActivity.this, list);
    listview.setOnItemClickListener(itemclick);
    }else{
    Toast.makeText(this, "此计划数据未能读取,请重新登录读取数据!", Toast.LENGTH_SHORT).show();
    }
    } class BackButtonClickListener implements OnClickListener
    { @Override
    public void onClick(View arg0) {
    // TODO 自动生成的方法存根
    finish();
    }

    }
    }
    package lht.inspection.overrideadapter;import java.io.FileNotFoundException;
    import java.util.ArrayList;import lht.inspection.activity.R;
    import lht.inspection.common.XmlResolve;
    import lht.inspection.model.Equipment;
    import android.content.Context;
    import android.graphics.Color;
    import android.graphics.drawable.BitmapDrawable;
    import android.view.Gravity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AbsListView;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.LinearLayout.LayoutParams;
    import android.widget.TextView;public class EquipmentActivityListviewAdapter extends BaseAdapter { private Context context;
    private ArrayList<Equipment> list;
    public EquipmentActivityListviewAdapter(Context c, ArrayList<Equipment> list){
    this.context = c;
    this.list = list;
    }
    @Override
    public int getCount() {
    // TODO 自动生成的方法存根
    return list.size();
    } @Override
    public Object getItem(int arg0) {
    // TODO 自动生成的方法存根
    return list.get(arg0);
    } @Override
    public long getItemId(int arg0) {
    // TODO 自动生成的方法存根
    return arg0;
    } @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
    // TODO 自动生成的方法存根
    XmlResolve xr = new XmlResolve(context);
    if(!xr.isFileEXists("equipmentsetting_file.xml")){
    String s = xr.SetSetting("");
    xr.WriteToXml(context, "equipmentsetting_file.xml", s);
    }
    String str = "";
    try {
    str = xr.GetSetting("equipmentsetting_file.xml");
    } catch (FileNotFoundException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    if(str != "" && str != null){
    String[] strs = str.split("\\*");
    LinearLayout linearLayout = new LinearLayout(context);//此布局为listview的布局,所以params的设置用AbsListView的。
    linearLayout.setLayoutParams(new AbsListView.LayoutParams(android.widget.AbsListView.LayoutParams.FILL_PARENT, android.widget.AbsListView.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setBackgroundResource(R.drawable.selector_1);
    ImageView iv = new ImageView(context);
    android.widget.AbsListView.LayoutParams absparam = new AbsListView.LayoutParams(android.widget.AbsListView.LayoutParams.WRAP_CONTENT,android.widget.AbsListView.LayoutParams.WRAP_CONTENT);
    iv.setLayoutParams(absparam);
    iv.setImageResource(R.drawable.btn4);
    LinearLayout subLinearLayout = new LinearLayout(context);
    subLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    subLinearLayout.setOrientation(LinearLayout.VERTICAL);
    String text = "";
    for(int i = 0;i < strs.length; i++){
    if(strs[i].equals("sbkpbh")){
    text += list.get(position).sbkpbh.toString() + "  ";
    }else if(strs[i].equals("mc")){
    text += list.get(position).mc.toString() + "  ";
    }else if(strs[i].equals("ggxh")){
    text += "型号:" + list.get(position).ggxh.toString() + "  ";
    }else if(strs[i].equals("zqdw")){
    text += list.get(position).zqdw.toString() + "  ";
    }else if(strs[i].equals("djzq")){
    text += "周期:" + list.get(position).djzq.toString() + " ";
    }else if(strs[i].equals("wbdw")){
    text += "外包单位:" + list.get(position).wbdw.toString() + "  ";
    }else if(strs[i].equals("djyq")){
    text += list.get(position).djyq.toString() + "  ";
    }else if(strs[i].equals("jtyq")){
    text += list.get(position).jtyq.toString() + "  ";
    }else if(strs[i].equals("bz")){
    text += list.get(position).bz.toString() + "  ";
    }

    }
    String s = "当前设备有 " + list.get(position).djxm_sl.toString() + " 项点检项目";
    TextView tv = new TextView(context);
    if(text.length() > 17){
    text = text.substring(0, 16) + "...";
    }
    tv.setText(text);
    tv.setPadding(5, 0, 0, 0);
    tv.setTextColor(Color.rgb(0, 0, 0));
    tv.setTextSize(20);
    tv.setGravity(Gravity.LEFT);
    LayoutParams lparams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
    lparams.setMargins(0, 2, 0, 0);
    tv.setLayoutParams(lparams);
    subLinearLayout.addView(tv);

    tv = new TextView(context);
    tv.setText(s);
    tv.setPadding(5, 0, 0, 0);
    tv.setTextColor(Color.rgb(150, 150, 150));
    tv.setGravity(Gravity.LEFT);
    LayoutParams lparam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
    lparam.setMargins(0, 2, 0, 2);
    tv.setLayoutParams(lparam);
    subLinearLayout.addView(tv);
    linearLayout.addView(iv);
    linearLayout.addView(subLinearLayout);
    return linearLayout;
    }
    else{
    view = LayoutInflater.from(context).inflate(R.layout.equipmentlistview_item_new, null);
    ImageView iv = (ImageView)view.findViewById(R.id.myimageview);
    iv.setImageResource(R.drawable.btn4);
    TextView tv1 = (TextView)view.findViewById(R.id.equipment_firstext);
    tv1.setTextColor(Color.rgb(0, 0, 0));
    tv1.setTextSize(20);
    TextView tv2 = (TextView)view.findViewById(R.id.equipment_secondtext);
    tv2.setTextColor(Color.rgb(150, 150, 150));
    tv1.setText(list.get(position).mc.toString());
    tv2.setText("当前设备有 " + list.get(position).djxm_sl.toString() + " 项点检项目");
    return view;
    }
    }
    }
    这是出问题的界面的代码,请各位帮忙看看吧。
      

  5.   

    我想可能是内存消耗太大,导致内存不足,系统就会自动回收掉你的activity2
      

  6.   

    再说,就算是内存消耗太大,因为activity2是当前的活动界面,系统也不应该把它杀死吧。
      

  7.   

    在logcat里面,我也没有看到什么有用的东西。
      

  8.   

    内存占用过大,android自动回收了
      

  9.   

    在eclipse的ddms里可以看到内存的使用情况,你看看是不是内存点用过大了。
      

  10.   

    楼主, 你的代码里面没有两个Activity啊,第一个是Activity    第二个是重写的listAdapter啊
      

  11.   

    多谢大家的帮助,我的问题解决了,跟大家分享下经验吧。看了大家的意见后,我就在想是不是真的是内存的问题呢?我就又去跑程序,死命的看logcat的输出。
    fatal signal 11 (sigsegv) 好吧,此错误一出现,我就知道程序应该是存在内存泄漏的问题了。后来发现应该是程序中调用xml文件时某些文件流没有调用.close()方法导致的内存泄漏。改正后重新运行程序,这个错误依旧存在。这时我就想,会不会是别的什么异常或者是错误导致的内存问题呢。没有办法,只能重新查看log了。
    图中的异常进入了我的眼中。仔细地对比此异常前后的输出信息,终于罪魁祸首就是它了,是它导致的当前界面不可用。原来是因为程序中的jni调用问题。在jni的c\c++程序中,由java传递过来的对象都存放在referencetable里,但是referencetable只能存储1024个对象,也就是说处理完的java对象需要及时释放,否则一旦referencetable被添满,程序就要出问题了。结贴了。
      

  12.   

    好像图片挂掉了,补充一下,异常是“reference table overflow (max=1024)”.