Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android onStop在进入主屏幕时调用vs onPause_Android_Android Lifecycle_Android Ondestroy - Fatal编程技术网

Android onStop在进入主屏幕时调用vs onPause

Android onStop在进入主屏幕时调用vs onPause,android,android-lifecycle,android-ondestroy,Android,Android Lifecycle,Android Ondestroy,我继承了一个启动活动a的项目,而活动a又启动了活动B。如果我按下安卓主页按钮,然后再次单击应用程序图标,我会得到活动a和活动B 看看生命周期,我看到了这一点 Click Icon ->Activity A Launch->onCreate->onStart->onResume Click on context menu that starts Activity B->onCreate->onStart->onResume Click on Android

我继承了一个启动活动a的项目,而活动a又启动了活动B。如果我按下安卓主页按钮,然后再次单击应用程序图标,我会得到活动a和活动B

看看生命周期,我看到了这一点

Click Icon ->Activity A Launch->onCreate->onStart->onResume
Click on context menu that starts Activity B->onCreate->onStart->onResume
Click on Android Home Button Activity B->onPause 
Click on App Icon on the Android Home Screen (to resume)
Activity B's onDestory is called followed by Activity A ->onCreate->onStart->onResume.
关于寻找什么会导致onDestroy vs onResume的高层次想法

舱单声明:

Activity A


 <activity
            tools:replace="android:theme,android:label"
            android:name="WebViewActivity"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name_pro"
            android:launchMode="singleTask"
            android:theme="@style/MyTheme.AppCompat.NoAB">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
            </intent-filter>

            <meta-data
                android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                android:resource="@xml/device_filter"/>
        </activity>

============================

Activity B

<activity
            android:name="OwaViewerActivity"
            android:label="@string/owa"
            tools:replace="android:theme"
            android:launchMode="singleTop"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:theme="@style/MyTheme.AppCompat.NoAB"
            android:parentActivityName="WebViewActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="WebViewActivity"/>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH"/>
            </intent-filter>
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable"/>
        </activity>
活动A
============================
活动B

因此,如果有疑问,请创建一个简单的应用程序。原来home按钮确实会生成一个onStop,如果点击图标重新启动,则应该调用onStart和on Resume。事实证明,单任务是导致故事发生的原因。如果我删除了SingleTask,应用程序就会正常工作。现在,我必须返回并找出遗留代码为什么使用单个任务

请从清单中粘贴相关部分好吗?为了获得一些内存,系统会杀死你的应用程序活动,因此这种行为不会持续发生,如果不需要内存,系统不会删除你的应用程序堆栈,你将从你开始结束(在活动B的resum中)。活动是启动程序活动吗?如果是,那么你可能会面临这样的问题@NinjaCoder是的,这是启动程序应用程序。我来看看你的链接你玩过启动模式吗?尝试删除清单中的这些属性,以查看是否修复了生命周期。如果是这样,你至少会知道从哪里开始寻找。