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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -