大家好我在这个网站上找到了putEtras的答案,但是当我尝试使用它我的应用程序崩溃时,我已经尝试了一切并且没有发现错误。我相信它是小的但是我无法检测到这是什么我再一次在这里寻求帮助......
头等舱:
package com.orion.peky.thetapgame;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.ads.*;
public class Game extends Activity {
TextView tekst, vrijeme;
int brojac=0, provjera=0;
CountDownTimer Count;
Intent i =new Intent(Game.this,Score.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
tekst=(TextView)findViewById(R.id.tekst);
vrijeme=(TextView)findViewById(R.id.vrijeme);
/*AdView adView=(AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);*/
Count = new CountDownTimer(10000, 1) {
public void onTick(long millisUntilFinished) {
int seconds = (int) ((millisUntilFinished / 1000));
vrijeme.setText(seconds + "." + millisUntilFinished % 1000);
}
public void onFinish(){
i.putExtra("prijenos",brojac);
startActivity(i);
finish();
}};
}
public void broji(View view){
if(provjera==0){
Count.start();
brojac++;
provjera++;
tekst.setText("Tapped " + brojac + " times");
}else {
brojac++;
tekst.setText("Tapped " + brojac + " times");
}
}
}
第二项活动:
package com.orion.peky.thetapgame;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class Score extends Activity {
int primljeno=1;
TextView prikazati=(TextView)findViewById(R.id.prikazbodova);
Bundle dodatak;
Intent inte=getIntent();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
dodatak=inte.getExtras();
primljeno=dodatak.getInt("prijenos");
prikazati.setText("You tapped "+primljeno+" times");
}
}
我已经找到了一些答案,例如: How to put Extras to different activity? 但是在开始第二项活动时仍然存在一些问题。 我知道adView是qouted但我不想创建假装载! 请不要将此标记为重复,因为它不是! :d
答案 0 :(得分:0)
您的问题是,在实际附加活动之前,您过早地呼叫Intent inte=getIntent();
和TextView prikazati=(TextView)findViewById(R.id.prikazbodova);
。移动
Intent inte=getIntent();
TextView prikazati=(TextView)findViewById(R.id.prikazbodova);
在onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
Intent inte=getIntent();
dodatak=inte.getExtras();
TextView prikazati=(TextView)findViewById(R.id.prikazbodova);