Android:你如何在点击时转到另一个活动?
2022-09-02 19:51:10
我正在尝试按顺序转到第三个活动。从主活动转到第二个活动工作正常,但是当我尝试从第二个活动转到第三个活动时,应用程序崩溃了。
以下是我对第二个活动的代码:
package com.example.helloandroid;
import android.app.Activity;
//other imports here
public class Game extends Activity implements OnClickListener {
private static final String TAG = "Matrix";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.matrix);
View doneButton = findViewById(R.id.done_button);
doneButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Intent k = new Intent(this, GameTwo.class);
startActivity(k);
//finish();
break;
}
}
}
第三个活动的代码:
package com.example.helloandroid;
import android.app.Activity;
//other imports here
public class GameTwo extends Activity {
private static final String TAG = "Matrix";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.matrixtwo);
View donetwoButton = findViewById(R.id.donetwo_button);
}
}