解决方案 »

  1.   

    试了,没用。这个工程一个月之前还能正常运行的。但是一个月后从svn版本库拿出来后就变成这样了。为什么连xml文件的界面没导入进去就自动退出了呢,而且通过log日志看,自动退出调用了onpause函数,但没调用ondestory函数,真的好奇怪,也没报错,就是自动退出
      

  2.   

    不好意思,只能手机操作,贴代码不太方便,刚刚找到问题原因了,我在Ondestroy函数里调用了Sysapplication.getinstance().exit()这个函数,用于退出应用程序。只是不太明白为什么Oncreate执行完后,我没有任何操作,就直接执行了上述那个Sysapplication.getinstance().exit函数,照理说只有ondestory函数执行时才会调用它。
      

  3.   

    如果Sysapplication.getinstance().exit() 提前调用了的话,是不会调用onDestroy的
      

  4.   

    同楼上猜测你提前调用了Sysapplication.getinstance().exit()
      

  5.   

    代码如下:
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graphs);
    SysApplication.getInstance().addActivity(this);
    // /////////////////////使应用程序图标可以被单击//////////////////////////////
    ActionBar actionBar = getActionBar();
    actionBar.hide();
    actionBar.setDisplayHomeAsUpEnabled(false);
    // ///////////////////////////////////////////////
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // ////////////////////使屏幕横向///////////////////////////////
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    Log.i("tip1111", "使屏幕横向");
    // ////////////////////////
    //获取能被本应用程序读,写的sharedPreferences对象
    preferences=getSharedPreferences("sleepmonitor",MODE_PRIVATE);
    editor=preferences.edit();
    //读取sharedpreference数据
    orinA=preferences.getFloat("orinA", (float) 0);
    orinB=preferences.getFloat("orinB", (float)0);
    BreathA=preferences.getFloat("BreathA", (float) 0);
    BreathB=preferences.getFloat("BreathB", (float)0);
    ECGA=preferences.getFloat("ECGA", (float) 0);
    ECGB=preferences.getFloat("ECGB", (float)0);
    Log.i("tip1111", "从preferences取数 "+ECGB);
    //第一次取数均为0,故需要判断,若第一次取数,则需要重新赋值
     if (orinA==0) {
    orinA=1;
    BreathA=1;
    ECGA=1;

    }
    // ////////////////////////
    init();
    // ////////////////////////
    //在界面中显示心率和呼吸率
    try {
      myHandler = new Handler(){
    @Override
    public void handleMessage(Message m){
    if (m != null) {

    if(m.what == 0x02){

        ECG_textview.setText(String.valueOf(BCGData_num));
    breath_textview.setText(String.valueOf(Breath_num));
    }
     
     
    }
    }
    };
    } catch (Exception e) {
    Log.e("eee", e.getMessage());
    // TODO: handle exception
    }
    }
    private void init() {


    // ///////////////////////////////////////////////////////////////////
    /**
     * 获取屏幕宽度
     */
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) this
    .getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    screenHeight = dm.heightPixels; layouts[0] = (LinearLayout) findViewById(R.id.graph1);
    layouts[1] = (LinearLayout) findViewById(R.id.graph2);
    layouts[2] = (LinearLayout) findViewById(R.id.graph3);
    // BCGPeakNum=(TextView)findViewById(R.id.BCGPeakNum);
    Arrays.fill(graphsLastXValue, 0d);   for (int i = 0; i < graphSerieses.length; i++) {
    graphViews[i] = new LineGraphView(this, "");

      if (i==0) {
      graphSerieses[i] = new GraphViewSeries("原始",new GraphViewSeriesStyle(red, 3),new GraphViewData[] {});
    }
      if(i==1)
      {
      graphSerieses[i] = new GraphViewSeries("呼吸",new GraphViewSeriesStyle(yellow, 3),new GraphViewData[] {});
      }
      if (i==2) {
      graphSerieses[i] = new GraphViewSeries("心冲击",new GraphViewSeriesStyle(green, 3),new GraphViewData[] {});
    }
    graphViews[0].addSeries(graphSerieses[i]);
    //  graphView.setManualYAxis(true);
    //         graphView.setManualYAxisBounds(6, 0);

    if (SelfAdapt==false) {
    graphViews[i].setManualMaxY(true);
    if (i==0) {
    graphViews[i].setManualYAxisBounds(originalMax, originalMin);
    }
    else if (i==1) {
    graphViews[i].setManualYAxisBounds(breathMax, breathMin);
    }
    else {
    graphViews[i].setManualYAxisBounds(heartMax, heartMin);
    }
    }


    graphViews[i].setViewPort(1, 1000);
    graphViews[i].setScalable(true);
       graphViews[i].setShowHorizontalLabels(false);
        graphViews[i].setShowVerticalLabels(false);
    layouts[i].addView(graphViews[i]);
    }
            graphViews[0].setShowLegend(true);
    graphViews[0].setTitle("原始数据");
    graphViews[1].setTitle("呼吸数据");
    graphViews[2].setTitle("心动数据 ");
    graphViews[0].getGraphViewStyle().setHorizontalLabelsColor(Color.BLUE); // ///////////////////////生成弹出菜单//////////////////////////////////////////////
    View root = this.getLayoutInflater().inflate(R.layout.popup, null);
    root.setAnimation(AnimationUtils.loadAnimation(this,
    R.anim.abc_fade_out));
    popmenu = new PopupWindow(root, LayoutParams.WRAP_CONTENT,
    screenHeight, true);
    popmenu.setFocusable(true);
    popmenu.setOutsideTouchable(true);
    root.setFocusable(true);
    // ////////////////////////////////////////////////////////////////////////////////
    LinearLayout linearLayout = (LinearLayout) root
    .findViewById(R.id.settings);
    // linearLayout.setBackgroundColor(Color.LTGRAY);
    popmenu.setBackgroundDrawable(new ColorDrawable(-0000));
    linearLayout.setFocusableInTouchMode(true);
    linearLayout.setOnKeyListener(new OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_MENU) && (popmenu.isShowing())) {
    popmenu.dismiss();
    return true;
    }
    return false;
    }
    });
    // /////////////////////////////////////////////////////////////////////////////////////////////
    tvMessage = (TextView) root.findViewById(R.id.tvMessage);
    tvX = (TextView) root.findViewById(R.id.tvX);
    tvY = (TextView) root.findViewById(R.id.tvY);
    breath_textview=(TextView)findViewById(R.id.breath_textview);
    ECG_textview=(TextView)findViewById(R.id.ECG_textview);
    xinlv=(TextView)findViewById(R.id.xinlv);
    huxi=(TextView)findViewById(R.id.huxi); btnStart = (Button) root.findViewById(R.id.btnStart);
    Log.i("tip1111", "find the btnstart");
    btnStart.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Log.i(TAG, "entering Button Start....");
    // Log.e("tip", "the startRecv is beginning");
    startDraw();
    startRecv();

    btnStart.setEnabled(false);
    btnStop.setEnabled(true);
    }
    });
    btnStop = (Button) root.findViewById(R.id.btnStop); btnStop.setOnClickListener(new View.OnClickListener() { @Override
    public void onClick(View arg0) {
    // TODO Auto-generated method stub
    if (datareceiver != null) {
    datareceiver.setRunning(false);
    } setRunning(false); try {
    if (bos!=null) {
    bos.close();
    bos = null;
    }

    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } btnStart.setEnabled(true);
    btnStop.setEnabled(false);
    }
    });
    btnExit = (Button) root.findViewById(R.id.btnExit);
    btnExit.setOnClickListener(new View.OnClickListener() { @Override
    public void onClick(View arg0) {
    Log.i(TAG, "entering Button Start....");
    // finish();
    SysApplication.getInstance().exit();
    }
    });
    public void onPopupChanneClick(View button)
    {
    final Button channelButton=(Button)findViewById(R.id.channelbtn);
    // 创建PopupMenu对象
    popup = new PopupMenu(getBaseContext(), channelButton);
    Log.e("btn", "after create");
    // 将R.menu.popup_menu菜单资源加载到popup菜单中
    getMenuInflater().inflate(R.menu.selectchannel, popup.getMenu());
    Log.e("btn", "before1111");
    // 为popup菜单的菜单项单击事件绑定事件监听器
    try {
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
    if(item.isCheckable())
    {
    item.setChecked(true);  //②
    }
    switch (item.getItemId()) { case R.id.channel1:
    Log.e("btn", "before2222222");
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道1");
    setSelectChannel(0);
    break;
    case R.id.channel2:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道2");
    setSelectChannel(1);
    break;
    case R.id.channel3:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道3");
    setSelectChannel(2);
    break;
    case R.id.channel4:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道4");
    setSelectChannel(3);
    break;
    case R.id.channel5:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道5");
    setSelectChannel(4);
    break;
    case R.id.channel6:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道6");
    setSelectChannel(5);
    break;
    case R.id.channel7:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道7");
    setSelectChannel(6);
    break;
    case R.id.channel8:
    if (item.isChecked()) {
    item.setChecked(false);
    }
    else {
    item.setChecked(true);
    }
    channelButton.setText("通道8");
    setSelectChannel(7);
    break;
    }
    Log.e("btn", "before222222233333");
    return true; }
    });
    popup.show(); } catch (Exception e) {
    // TODO: handle exception
    Log.e("btn", e.getMessage());
    }

    }
    private void startGraphActivity(Class<? extends Activity> activity) {
    Intent intent = new Intent(Drawer.this, activity);
    intent.putExtra("type", "line");
    startActivity(intent);
    } @Override
    protected void onPause() { super.onPause();
    Log.i("Lifecycle", "In the onPause() event");
    }
    @Override
    public void onDestroy(){
    super.onDestroy();
    Log.e("Lifecycle", "In the onDestory() event");
    // SysApplication.getInstance().exit();

    }
    把onDestroy()的SysApplication.getInstance().exit();屏蔽,程序不会自动退出,没有屏蔽就就死了。
    我感觉程序只有在退出时候才会执行 onDestroy()吧,为啥加了SysApplication.getInstance().exit();之后我没有按退出键,他也执行onDestroy()这个函数?