Java / Androif创建一个意图,说明您想要启动哪个Activity

时间:2016-03-11 23:08:16

标签: java android

我试图创建一个意图,说明我想要启动哪个活动。我想我是正确的,因为我一直在Cannot resolve constructor部分获得this, ActivityTwo.class。我想要启动的活动是ActivityTwo.java

    Button launchActivityTwoButton = (Button) findViewById(R.id.bLaunchActivityTwo);
    launchActivityTwoButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO:
            // Launch Activity Two
            // Hint: use Context's startActivity() method

            // Create an intent stating which Activity you would like to
            // start

            Intent intent = new Intent(this, ActivityTwo.class);

            // Launch the Activity using the intent
             startActivity(intent);
        }
    });

1 个答案:

答案 0 :(得分:0)

this替换为WhateverYourActivityIs.this,其中WhateverYourActivityIs是您的代码所在的活动类的名称。

或者,如果此代码位于片段中,请将this替换为getActivity()