本文介紹了Android:你如何通過點擊進(jìn)入另一個活動?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在嘗試依次進(jìn)行第三個活動.從主要活動轉(zhuǎn)到第二個活動很好,但是當(dāng)我嘗試從第二個活動轉(zhuǎn)到第三個活動時,應(yīng)用程序崩潰了.
I'm trying to move onto the third activity in a sequence. Going from the main activity to the second one works fine but when I try to go to the third activity from the second I the application crashes.
這是我的第二個活動的代碼:
Here's my code for the second activity:
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;
}
}
}
以及第三個活動的代碼:
And the code for the third activity:
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);
}
}
推薦答案
在switch
中試試下面的代碼:
try {
Intent k = new Intent(Game.this, GameTwo.class);
startActivity(k);
} catch(Exception e) {
e.printStackTrace();
}
告訴我這有用嗎.....
Tell me is this helpful.....
這篇關(guān)于Android:你如何通過點擊進(jìn)入另一個活動?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!