converting a string to a class

后端 未结 2 1739
傲寒
傲寒 2021-01-03 07:27

I\'m trying to move between one Activity to another based upon some user input.

I\'m trying to use:

String myClass = \"some_user_input.class\"
Intent         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 07:57

    This is my solution using Class.forName() method:

    String myClass = "foo.class";
    Intent i = new Intent(getApplicationContext(), Class.forName(myClass));
    startActivity(i);
    

提交回复
热议问题