【发布时间】:2014-11-02 05:13:24
【问题描述】:
我正在尝试创建一个按钮,一旦单击,该按钮将转到另一个活动 FourthActivity,但我的 Logcat 上不断收到以下错误:“Choreographer:跳过 121 帧!应用程序可能在其主服务器上做了太多工作线。”我做了一些研究,发现使用AsyncTask 可以摆脱它,但我不知道该怎么做。谁能帮我?谢谢!
下面是ThirdActivity.java的代码:
package elena.crosscountry.app;
import android.app.Activity;
import android.widget.Button;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.content.Intent;
public class ThirdActivity extends Activity implements View.OnClickListener {
Button staart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
staart = (Button) findViewById(R.id.staart);
staart.setOnClickListener(this);
}
private void staartClick(){
startActivity(new Intent(ThirdActivity.this, FourthActivity.class));
}
public void onClick(View view){
switch(view.getId()){
case R.id.staart:
staartClick();
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.third, menu);
return true;
}
}
下面是activity_third.xml的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ThirdActivity" >
<Button
android:id="@+id/staart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start" />
</LinearLayout>
【问题讨论】:
-
我在主线程上看不到任何繁重的工作,这是完整的代码吗?
-
这可能是导致错误的另一件事。不是
Intent。FourthActivity.class中有什么内容?