为什么我的意图不起作用?

时间:2013-04-23 02:26:07

标签: android android-intent

我有以下代码:

public class P1R1 extends Activity {

    int correctCounter;
    private String[] answerString;
    private TextView score;
    private static final Random rgenerator = new Random();
    protected static final String EXTRA_playerOneScore = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.level);

        score = (TextView) findViewById(R.id.score);

        correctCounter = 0;

        loadActivity();
        //start round timer
        new CountDownTimer(60000, 1000) {

            final TextView timer = (TextView) findViewById(R.id.timer);


            public void onTick(long millisUntilFinished) {
                timer.setText("Time: " + millisUntilFinished / 1000 + "s");
            }

            public void onFinish() {
                Intent roundOneToTwo = new Intent(getActivity(), R1R2.class);
                String playerOneScore = String.valueOf(correctCounter);
                roundOneToTwo.putExtra(EXTRA_playerOneScore, playerOneScore);
                startActivity(roundOneToTwo);
            }
         }.start();

我有一个计时器正在运行,当计时器结束时,我希望运行Intent,但我的意图是The constructor Intent(new CountDownTimer(){}, Class<R1R2>) is undefined我收到错误。

我确实创建了一个R1R2类,但我的Intent仍然出错。我还是Android的新手,所以如果你能提供帮助就会很棒。谢谢!

1 个答案:

答案 0 :(得分:0)

取代

Intent roundOneToTwo = new Intent(this, R1R2.class);

尝试

Intent roundOneToTwo = new Intent(P1R1.this, R1R2.class);

Intent构造函数的第一个参数应该是Context,但是您要传递对CountDownTimer的引用。见http://developer.android.com/reference/android/content/Intent.html