简体   繁体   English

我如何将通用类作为参数传递给Intent构造函数

[英]How can i pass a generic class as param to Intent constructor

I have this generic activity in my android application 我的Android应用程式中有这项一般活动

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. 但是,Intent构造函数不接受泛型类作为参数。 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? 任何人都知道如何将通用类作为参数传递给Intent构造函数?

Thanks 谢谢

I don't believe that android Intent System supports Generic activities and you shouldn't just create an activity object your self. 我不相信android Intent System支持Generic活动,并且您不应该只创建自己的活动对象。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM