Skip to content

Instantly share code, notes, and snippets.

@sgnn7
Created December 16, 2011 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgnn7/1487133 to your computer and use it in GitHub Desktop.
Save sgnn7/1487133 to your computer and use it in GitHub Desktop.
Android - opening activity from class name
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;
}
}
@sushantsomani2310
Copy link

What is target parameter in getActivityClass method?

@xi9lulu
Copy link

xi9lulu commented Jun 26, 2023

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