java - How to set target activity with variable -
how can use variable in intent target activity?
string var1 = et.gettext().tostring(); intent intent = new intent(mainactivity.this,mainactivity2.class);//mainactivity2.class => var1
here's how:
try { // considering var1 = mainactivity2 class cls = class.forname("package.name." + var1); intent intent = new intent(mainactivity.this, cls); startactivity(intent); } catch (classnotfoundexception e) { e.printstacktrace(); }
Comments
Post a Comment