Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中通过intent传递整数变量?_Android_Android Intent_Integer - Fatal编程技术网

如何在android中通过intent传递整数变量?

如何在android中通过intent传递整数变量?,android,android-intent,integer,Android,Android Intent,Integer,我以前尝试过通过Intent传递变量。但是我似乎错过了一些我不能通过整数变量时间的东西。这个问题以前有人问过,但在这种情况下,我无法让它起作用 我想通过intent将整数变量time的值传递给另一个类,该类是postpap.class 我有这个密码 public class ingame extends Activity { private TextView textTimer; int time = 0; Timer t; TimerTask task; @Override prot

我以前尝试过通过Intent传递变量。但是我似乎错过了一些我不能通过整数变量时间的东西。这个问题以前有人问过,但在这种情况下,我无法让它起作用

我想通过intent将整数变量time的值传递给另一个类,该类是postpap.class

我有这个密码

public class ingame extends Activity {
private TextView textTimer;
int time = 0;  
Timer t;  
TimerTask task;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ingame);
    Button button = (Button)findViewById(R.id.my_button);
    final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)button.getLayoutParams();

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

    params.leftMargin = button.getWidth()+ new Random().nextInt(displaymetrics.widthPixels - 2*button.getWidth());
    params.topMargin = button.getHeight()+ new Random().nextInt(displaymetrics.heightPixels - 3*button.getHeight());
    Log.v("widthPixels", ""+ displaymetrics.widthPixels);
    Log.v("heightPixels", ""+ displaymetrics.heightPixels);
    button.setLayoutParams(params);
    startTimer();

    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
              t.cancel();  
              t.purge(); 

            //Starting a new Intent
              Intent thirdscreen = new Intent(getApplicationContext(), aftertap.class);

                //Sending data to another Activity
                thirdscreen.putExtra("time", time);
                startActivity(thirdscreen);
        }
    });
}
public void startTimer(){  
      t = new Timer();     
      task = new TimerTask() {  

        @Override  
       public void run() {  
        runOnUiThread(new Runnable() {  

          @Override  
         public void run() {
              textTimer = (TextView) findViewById(R.id.textTimer);
              textTimer.setText(time + "");  
              time = time + 1;  
         }  
        });  
       }  
      };  
      t.scheduleAtFixedRate(task, 0, 1);  
     }  
}
后处理类:

public class aftertap extends Activity{
TextView score;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aftertap);
    TextView gameover = (TextView)findViewById(R.id.gameover);
    score = (TextView)findViewById(R.id.score);

    Intent i = getIntent();
    // Receiving the Data
   //I do not know how to get the value of the integer variable time. I want to display the value of time in the TextView score
}
}
您应该使用以下方法:

将默认值参数(第二个参数)更改为所需的值

然后显示值

score.setText(String.valueOf(value));

如何在textview分数中显示可变时间的值?出现了什么错误?
score.setText(String.valueOf(value));