Amazon Gift Cards

Thursday, January 6, 2011

Opening an Activity with string in Android

This question has been asked here and and my problem is similar but i cant see the destination classes coz the classes are from different libraries and therefore i need to open an activity based on just the string and here is how i fixed mine:

try {
  String className = 'com.almondmendoza.library.openActivity';
  Intent openNewIntent = new Intent( this, Class.forName( className ) );
  startActivity(  openNewIntent );
} catch (ClassNotFoundException e) {

Here we use reflections and just convert our class name to a class object.

If you are interested in reflection we had blogged about it previously Access internal classes in Android and Calling Private Methods in Android