【问题标题】:Activity not being called未调用活动
【发布时间】:2018-12-30 02:20:55
【问题描述】:

我有一个调用活动的函数,但没有调用该活动,而是调用了 MainActivity。据我所知,这次通话并没有什么不寻常的地方。我可以通过activity的源代码一路跟踪intent,我看到intent就是想要的activity。

我创建意图:

Intent startNewActivityOpen2 = new Intent(this, com.assistek.ediary.TransitionLandscape.class);
setExtrasStartActivity(startNewActivityOpen2, extras);

这是我调用的方法:

protected void setExtrasStartActivity(Intent i, Bundle extras) {
    // copy over all extras
    if (extras != null) {
        if (!extras.isEmpty()) {
            i.putExtras(extras);
        }
    }

    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    //I can see here that the the intent is correct
    startActivity(i);
    finish();

}

Logcat:

12-10 19:09:56.041 2857-2857/com.assistek.ediary D/Base 活动:**********暂停类 com.assistek.ediary.TransitionLandscape **********暂停导航:真 ********** 继续上课 com.assistek.ediary.TransitionLandscape **********暂停类com.assistek.ediary.TransitionLandscape **********暂停导航:假 12-10 19:09:56.061 539-9188/? I/ActivityManager:从 pid 0 开始 u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.assistek.util.homelauncher/.HomeLauncherActivity} 12-10 19:09:56.181 2857-2857/com.assistek.ediary D/Base 活动:**********焦点:错误活动:com.assistek.ediary.TransitionLandscape 类 12-10 19:09:56.191 1002-1006/? D/dalvikvm: GC_CONCURRENT freed 479K, 12% free 7739K/8708K, paused 3ms+3ms,总共34ms 12-10 19:09:56.191 539-22740/? I/ActivityManager:从 pid 开始 u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.assistek.ediary cmp=com.assistek.ediary/.Home} 1002 12-10 20:19:49.371 1002-1006/? D/dalvikvm:GC_CONCURRENT释放842K,11%释放7767K/8708K,暂停3ms+1ms,共48ms 12-10 20:19:49.501 539-620/? D/dalvikvm:GC_FOR_ALLOC释放241K,19%释放16643K/20352K,暂停58ms,共59ms 12-10 20:19:49.501 539-620/? I/dalvikvm-heap:将堆(碎片情况)增加到 16.531MB,分配 251120 字节 12-10 20:19:49.561 539-620/? D/dalvikvm:GC_FOR_ALLOC释放4K,19%释放16884K/20600K,暂停56ms,共56ms 12-10 20:19:49.621 539-620/? D/dalvikvm: GC_FOR_ALLOC freed 262K, 20% free 16621K/20600K, paused 58ms,总共58ms 12-10 20:19:49.621 539-27162/? I/ActivityManager: moveTaskToBack: 5106 12-10 20:19:49.641 539-22745/? I/ActivityManager:从 pid 0 开始 u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.assistek.util.homelauncher/.HomeLauncherActivity} 12-10 20:19:49.661 6240-6240/com.assistek.ediary D/Base Activity: **********Stop Navigate Away false

为什么会调用 Home Launcher?

编辑:如果我调用另一个活动,则会显示正确的活动。

编辑:这是我的清单

    <activity
        android:name=".TransitionLandscape"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:noHistory="true"
        android:screenOrientation="landscape"
        android:windowSoftInputMode="stateHidden">
    </activity>

【问题讨论】:

  • 你试过删除 FLAG_ACTIVITY_CLEAR_TOP 吗?
  • @Anonymous 是的,结果相同
  • @KristyWelsh 向我们展示您的清单声明?
  • @Hades 这是我在编辑后的帖子中的清单声明。
  • “但是没有调用活动,而是调用了 MainActivity”到底是什么意思。 @克里斯蒂威尔士

标签: android android-intent


【解决方案1】:

com.assistek.ediary 是您应用的包名吗?

看起来您正在尝试调用以 HomeActivity 作为启动器活动的其他应用程序的活动,因此调用了它的 Home 活动。

 Intent secondActivityIntent= new Intent(getApplicationContext(), SecondActivity.class);              
 intent.putExtra("myKey", "MyValue");
 context.startActivity(secondActivityIntent);

【讨论】:

  • Kall 是的,come.assistek.ediary 是我的应用程序包名称。那么使用应用程序上下文会解决问题吗?
【解决方案2】:

我不能 100% 确定这是否是正确的答案,但值得一试,

    <activity
        android:name="com.assistek.ediary.TransitionLandscape"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:noHistory="true"
        android:screenOrientation="landscape"
        android:windowSoftInputMode="stateHidden">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

并确保您覆盖此内容而不是其他任何内容,

@Override
protected void onCreate(Bundle savedInstanceState) {
}

【讨论】:

  • 不,这不起作用。不过谢谢你的回答。
猜你喜欢
  • 1970-01-01
  • 2016-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多