我的android项目的活动正在跳过

时间:2015-06-20 07:21:21

标签: android android-intent android-activity

我创建了一个简单的android项目。但是,问题是其中所有3个活动中的第二个活动是跳过。 logcat显示的警告很少。

"Skipped 108 frames! The application may be doing too much work on its main thread."

我的第二项活动 -

EditText et1,et2,et3,et4;
Button btn;
int i,counter;
double theory_credit,theory_gp,lab_credit,lab_gp,total_credit,total_gp,cgpa;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_another);

    et1 = (EditText) findViewById(R.id.editText1);
    et2 = (EditText) findViewById(R.id.editText2);
    et3 = (EditText) findViewById(R.id.editText3);
    et4 = (EditText) findViewById(R.id.editText4);
    btn = (Button) findViewById(R.id.button1);

    String value=getIntent().getStringExtra("Input");
    counter=Integer.parseInt(value);
    theory_credit=theory_gp=lab_credit=lab_gp=total_credit=total_gp=cgpa=0.0;

    for(i=1;i<=counter;i++){


        btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                String inp;

                inp=et1.getText().toString();
                theory_credit=Double.parseDouble(inp);
                et1.setText("");
                inp=et2.getText().toString();
                theory_gp=Double.parseDouble(inp);
                et2.setText("");
                inp=et3.getText().toString();
                lab_credit=Double.parseDouble(inp);
                et3.setText("");
                inp=et4.getText().toString();
                lab_gp=Double.parseDouble(inp);
                et4.setText("");

                if(theory_gp>0.0 && theory_credit>0.0){
                    total_credit+=theory_credit;
                    total_gp+=(theory_gp*theory_credit);
                }

                if(lab_gp>0.0 && lab_credit>0.0){
                    total_credit+=lab_credit;
                    total_gp+=(lab_gp*lab_credit);
                }
            }
        });
    }

    if(total_credit>0.0){
        cgpa=total_gp/total_credit;
    }

    Intent intent=new Intent(AnotherActivity.this, FinalActivity.class);
    intent.putExtra("Result", cgpa);
    startActivity(intent);
}

我该如何解决这个问题? 我的第一和第三项活动运作良好。

2 个答案:

答案 0 :(得分:2)

无需在单个java类中添加两个布局。每个布局仅与一个类相关联。因此,在您的代码中,您已经编写了setContentView(R.id.yourLayout)两次,这是不需要的。而且,在单个UI线程中,您不能放置两个布局,这也可能是导致崩溃的一个原因。

答案 1 :(得分:0)

尝试从for循环中删除setContentView(R.layout.activity_another);。您已经在上面设置了自己的观点。你有什么原因把它放在里面吗?