我創建了一個簡單的android項目。但是,問題是所有3個活動中的第二個活動正在跳過。 logcat顯示幾個警告。我的android項目的活動正在跳過
"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);
}
我是如何解決這一問題? 我的第一和第三項活動運作良好。
你在模擬器或真實設備上測試過嗎?大多數時候,這個錯誤是由於模擬器速度緩慢。 –
在仿真器上或真實設備上運行應用程序時,您是否看到了這一點? – sandalone
我在模擬器和真實設備上都嘗試過。但結果相同。 –