我试图创建一个意图,说明我想要启动哪个活动。我想我是正确的,因为我一直在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);
}
});
答案 0 :(得分:0)
将this
替换为WhateverYourActivityIs.this
,其中WhateverYourActivityIs
是您的代码所在的活动类的名称。
或者,如果此代码位于片段中,请将this
替换为getActivity()
。