How can i pass a generic class as param to Intent constructor
I have this generic activity in my android application
public class NavegadorActivity<T> extends Activity {
....
...
}
And I'm trying to call it as below
Intent intent = new Intent(v.getContext(), NavegadorActivity<Clientes>.class);
However, Intent constructor doesn't accept a generic class as param. Then I tried this code
Class<NavegadorActivity<Clientes>> NavClientes = NavegadorActivity.class;
Intent intent = new Intent(v.getContext(), NavClientes.class);
Which doesn't work either.
Nor this
Class<NavegadorActivity<Clientes>> NavClientes = NavegadorActivity<Clientes>.class;
Intent intent = new Intent(v.getContext(), NavClientes.class);
Anyone know how can i pass a generic class as param to Intent constructor?
Thanks
I don't believe that android Intent System supports Generic
activities and you shouldn't just create an activity object your self. I suggest to add an inner class to your activity that represents the generic functionality and pass that generic name via
intent.putExtraString("class", yourClass.getName());
and retreive that class object via
Class<?> myGeneric = Class.forName(intent.getStringExtra("class", "java.Object");
怎么了
Intent intent = new Intent(v.getContext(), NavegadorActivity.class);
链接地址: http://www.djcxy.com/p/12502.html