【问题标题】:How can I set an intent's class from a string value?如何从字符串值设置意图的类?
【发布时间】:2010-06-10 21:16:10
【问题描述】:

我正在尝试将意图的类设置为字符串值中列出的地址,以便我可以启动给定的活动。字符串是在运行时动态组成的。

有没有办法让下面的代码运行:

String target=com.test.activity1.class;
Intent intent=new intent();
intent.setClass(this, target);

谢谢

【问题讨论】:

    标签: android string android-activity android-intent


    【解决方案1】:

    Intent 类有方法setClassName

    Intent intent = new Intent().setClassName(context,target);
    

    【讨论】:

      【解决方案2】:

      您可以尝试使用forName method of the Class class。

      无论如何,我一直想知道setClassName 方法的使用......它可能对你的情况有用

      【讨论】:

        猜你喜欢
        • 2021-01-21
        • 2011-05-17
        • 1970-01-01
        • 2011-07-12
        • 2014-03-10
        • 1970-01-01
        • 1970-01-01
        • 2020-01-19
        相关资源
        最近更新 更多