【问题标题】:How to retrieve the activity requested by an Intent如何检索 Intent 请求的活动
【发布时间】:2012-02-24 01:01:27
【问题描述】:

假设我有这样的意图:

 Intent intent = new Intent(context, MyActivity.class);

然后我想要一个方法,它会为以下情况返回 true:

 boolean found = intent.getSomeMethodToRetrieveActivity() instanceof MyActivity;

基本上有什么方法可以找出意图解析到的 Activity 吗?

有什么想法吗?

编辑

仔细阅读src,我可以看到我可以像这样获得类名:

 intent.getComponent().getClassName()

这将返回接近的“com.my.package.MyActivity”,但我想使用instanceof

【问题讨论】:

    标签: android class android-intent instanceof


    【解决方案1】:

    我刚刚在我的问题中使用了equals()

     intent.getComponent().getClassName()
    

    【讨论】:

      【解决方案2】:

      如何使用Java的反射机制,具体是Class.newInstance()Class.isInstance()方法?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-20
        • 2023-01-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-02
        • 2018-05-10
        • 1970-01-01
        相关资源
        最近更新 更多