Android应用程序再次调用MAIN /发射器,而不是onResume() [英] Android app calls MAIN/LAUNCHER again, instead of onResume()

查看:217
本文介绍了Android应用程序再次调用MAIN /发射器,而不是onResume()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序 - 活动B - 移动到背景(由用户pressing Android主键),它仍然活着,的onStop()如预期被称为

when my android app - Activity B - is moved to the background (by the user pressing the android home button), it is still alive, onStop() was called as expected.

活动B一直没有在这里被破坏,但是当用户点击应用程序的图标再次,它再次调用的意图过滤MAIN和LAUNCHER,开始活动A,而不是调用上的活动B. onResume()

Activity B has not been destroyed here, but when the user clicks on the app's icon again, it calls the intent-filter MAIN and LAUNCHER again, starting Activity A, instead of calling onResume() on Activity B.

所以发射活动显示 - 活动A - ,但如果用户presses回来的android按钮,然后启动活动结束()和老年活动 - 活动B - 显示!

so the launch activity is shown - Activity A - , but if the user presses android back button, then launch activity finishes() , and the old activity - Activity B - is shown!

什么时,活动B被移动到后台应该发生的是,活动B暂停和停止。当应用程序被pressing应用程序图标恢复,活动B应恢复。 (除非它被杀害和破坏,它一直没有)

what should happen when Activity B is moved to the background is that Activity B is paused and stopped. When the app is resumed by pressing the app icon, Activity B should be resumed. (unless it was killed and destroyed, which it hasn't been)

我该如何解决这个问题?活动B是通过活动A使用最初打开

How do I fix this? Activity B is originally opened by Activity A using

Intent next = new Intent(ActivityA.this, ActivityB.class);
startActivity(next);
finish();

下面是活动B

<activity android:name=".ActivityB"
    android:screenOrientation="portrait"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">
</activity>

下面是活动A

<activity android:name=".Activity A"
     android:screenOrientation="portrait"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

为什么会这样?我如何解决它?

why is this happening and how do I fix it?

推荐答案

使用的android:launchMode =singleTask在manifeast文件,其中声明b活动。然后活动B不是在后台显示。

Use android:launchMode="singleTask" in your manifeast file where you declare activity b. Then activity b not display in background.

这篇关于Android应用程序再次调用MAIN /发射器,而不是onResume()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆