0

Is it possible to do this in android:

String anewactivity="Zero";
Intent NewActivity = new Intent(context, anewactivity.class);

I tried to do that but it gave me an error. Is it possible in some way?

Thanks!

I saw the answer that you showed me when i was posting my question. but the other answer don't launch for me the new activity does it?

JamesAnd
  • 410
  • 1
  • 8
  • 28
  • 1
    This is supported in Java and is answered [here](http://stackoverflow.com/questions/6094575/creating-an-instance-using-the-class-name-and-calling-constructor). – Aaron D Mar 13 '15 at 14:18
  • you need the fully qualified path to the class, and then you can use intent.setClassName(context, anewactivity); – Blackbelt Mar 13 '15 at 14:24
  • ah k thanks! so whats the best method? the linked answer or the below reply (java reflection). any idea? :) – JamesAnd Mar 13 '15 at 14:26
  • 1
    ok got it! i am not in need of using the constructor so I'll be using the answer below! – JamesAnd Mar 13 '15 at 14:28

1 Answers1

5

You can use java's reflection methods:

Class activityClass = Class.forName("com.something.Zero");
João Ponte
  • 101
  • 1
  • 2