I would like to dynamically start an activity based on the previous activity's input. I have input a string through the previous activity, the only thing is this specific code throws the error
cannot resolve constructor 'Intent(com.MentalMathWorkout.EasyCountDown, java.lang.String)'
Is there a way to make this work?
public class EasyCountDown extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ecd);
Intent intent = getIntent();
String test = intent.getStringExtra(MainActivity.TEST_TYPE);
String cstring = ".class";
final String activity = test.concat(cstring);
Intent intent = new Intent(EasyCountDown.this, activity);
startActivity(intent); //Start test
}
I have a class on here:
My test string like that:
And it working good:
Dont forget you can use switch case or etc., because in this way you can get
ClassNotFoundException
and your intent will benull
.The ComponentName object does just that:
That's assuming
this
is an instance ofActivity
. (for aFragment
, usegetActivity()
, obv.)