我如何传递一个泛型类的参数,以构造意向 [英] How can i pass a generic class as param to Intent constructor
本文介绍了我如何传递一个泛型类的参数,以构造意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的Android应用程序这个通用的活动
I have this generic activity in my android application
public class NavegadorActivity<T> extends Activity {
....
...
}
和我想它调用如下
Intent intent = new Intent(v.getContext(), NavegadorActivity<Clientes>.class);
然而,意图构造函数不接受一个泛型类的参数。然后,我想这code
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);
这也不行。
这也不
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?
感谢
推荐答案
我不相信Android的意图系统支持通用
活动,你不应该只是创建一个活动对象你的自我。我建议通过
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());
并通过
Class<?> myGeneric = Class.forName(intent.getStringExtra("class", "java.Object");
这篇关于我如何传递一个泛型类的参数,以构造意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文