【问题标题】:Unable to find activity declared in other package找不到在其他包中声明的活动
【发布时间】:2012-04-20 06:38:12
【问题描述】:

在我的应用程序中单击一个按钮时,我想从另一个包启动一个活动。

这是我的意图:

  final Intent myIntent = new Intent(getApplicationContext(), com.facebook.android.Places.class)

这是我的清单:

<activity android:name=".com.facebook.android.Places"
            > </activity>

但我收到unable to find explicit activity com.mypackage\com.facebook.android.Places

从另一个包开始活动是不可能的吗?

【问题讨论】:

    标签: java android package


    【解决方案1】:

    不要从另一个库项目启动 Activity:

    创建你自己的子类:

    public class MyPlaces extends com.facebook.android.Places {
    
    @Override
       public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ...
       }
    }
    

    现在在你的 Manifest 中声明你的新 Activity:

    <activity android:name=".MyPlaces"> </activity>
    

    【讨论】:

    • 我只会创建一个子类并从其中的位置复制相同的代码,因为我不想做任何不同的事情?
    • 您要使用库项目还是启动另一个应用程序的活动?
    【解决方案2】:
    <activity android:name=".com.facebook.android.Places"> </activity> 
    

    com.facebook.android 包中的 Places 活动是否存在?还是在 com.mypackage.com.facebook.android 中?

    如果 Places 类在 com.facebook.android 中,请将清单条目更改为

    <activity android:name="com.facebook.android.Places"> </activity>
    

    你不必以“.”开头的名字

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-01
      • 2016-09-14
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多