相关疑难解决方法(0)

通过Intent传递数据并接收它

我试图通过我的Intent将数据传递到下一个活动,这样我就可以收到它并给出一个计时器值.

Button TimerButton = (Button)findViewById(R.id.TimerActivityButton);
TimerButton.setOnClickListener(new View.OnClickListener(){
     public void onClick(View v)
     {
          Intent timer = new Intent (BeefActivity.this,TimerActivity.class);
          timer.putExtra("beefType", 5000);
          timer.putExtra("beefThickness", 5000);
          timer.putExtra("grillTime", 15000);
          startActivity(timer);
      }
});
Run Code Online (Sandbox Code Playgroud)

我已经尝试了不同的接收值的方法,并且我不断收到强制关闭或编译器错误.我知道这很简单所以有人可以告诉我如何做到这一点.先感谢您!


This is force closing
Run Code Online (Sandbox Code Playgroud)
  • 我尝试传入int length = beefType并强制关闭
  • 我尝试将-1改为200,它仍然强制关闭
  • 我把int length = 20000放回去了

只是拥有int beefType = getIntent().getIntExtra("beefType", -1);我班级的顶级才能让它靠近.没有编译器错误.我被困了:-(这是我的代码看起来如何


package com.android.project1;

import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TimerActivity extends Activity {

    int beefType = getIntent().getIntExtra("beefType", 200);

  TextView timeDisplay;
  MyCount counter;
  int state = …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-activity

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-activity ×1

android-intent ×1