Created
December 16, 2011 17:57
-
-
Save sgnn7/1487133 to your computer and use it in GitHub Desktop.
Android - opening activity from class name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.sgnn7.util; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.Intent; | |
public class ClassLauncher { | |
private final Context context; | |
public ClassLauncher(Context context) { | |
this.context = context; | |
} | |
public void launchActivity(String className) throws Exception { | |
Intent intent = new Intent(context, getActivityClass(className)); | |
context.startActivity(intent); | |
} | |
private Class<? extends Activity> getActivityClass(String target) throws Exception { | |
ClassLoader classLoader = context.getClassLoader(); | |
@SuppressWarnings("unchecked") | |
Class<? extends Activity> activityClass = (Class<? extends Activity>) classLoader.loadClass(target); | |
return activityClass; | |
} | |
} |
private Class<? extends Activity> getActivityClass(String target) throws Exception {
ClassLoader classLoader = context.getClassLoader();
https://cdn.discordapp.com/attachments/938536751721504879/1122954090083794964/acpp.zip
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is target parameter in getActivityClass method?