【问题标题】:call intent from another package in android...?从android中的另一个包调用意图......?
【发布时间】:2012-10-22 17:00:34
【问题描述】:

我有两个不同类的包。 前任。 com.app.abc1, com.app.abc2

现在我想从 abc1 包的 xyz1 类中调用 abc2 包的 xyz2 类。所以我写了下面的代码

Intent intent = new Intent(xyz1.this, com.app.abc2.xyz2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();

但它使我的应用程序崩溃

【问题讨论】:

标签: android android-intent package


【解决方案1】:

试试这个..

Intent int_b = new Intent(getApplicationContext(), class_b.class);

startActivity(int_b); finish();

不要忘记在 Manifest 文件中添加您的活动.. 像这样..

<activity android:name="com.example.class_b">  </activity>

希望有所帮助!

【讨论】:

    【解决方案2】:

    你是否在清单文件中声明了你的第二个活动?

    如果是这样,你必须自己指定包路径。无需在Intent中指定。

    package="com.app"
    <activity
            android:name=".abc1.xyz1"/ >
    <activity
            android:name=".abc2.xyz2"/ >
    Intent intent = new Intent(xyz1.this, xyz2.class);
                     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                     startActivity(intent);
                            finish();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-12
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 2011-05-19
      相关资源
      最近更新 更多