vendredi 17 novembre 2017

How to implement Dynamic Android Activities

I am investigating what mechanisms are available within an Android application in an attempt to develop a "Dynamic application".

I wish to develop Activities that have "data driven" features. This controlling data is only available at runtime.

What I would like to achieve is to be able to dynamically instantiate classes that extend android.support.v7.app.AppCompatActivity

and that also implement multiple interfaces.

For inplementing public interfaces I can use Java Reflection and dynamic proxies with java.lang.reflect.InvocationHandler.

How can I implement private and/or package private interfaces?

How can I employ java reflection to instantiate a class that extends android.support.v7.app.AppCompatActivity and that also implements

multiple interfaces so that I can then start the class as an Android Activity.

final String baseClassName = "android.support.v7.app.AppCompatActivity";
final String[] interfaceNames = new String[]{"com.publik.vizible.ICanSeeAndUse", "org.pakage.pryvate.IHidden"}

Class<?> syntheticClass = constructActivityClass(baseClassName, interfaceNames);

final Intent intent = new Intent(this, syntheticClass);
startActivity(intent);

I do not believe I can use the "normal" byte code libraries such as javassist etc.

How is it possible within an Android application to achieve my desired result?





Aucun commentaire:

Enregistrer un commentaire