在 Android Studio 4.0 中按“运行”时,有时我的应用会在设备的后台启动 - 运行 Android 7.0 的平板电脑。这意味着我必须转到设备上的“最近的项目” View ,然后按那里的应用程序才能打开。该应用程序不会正常在前台启动。
发生这种情况时,Android Studio 的“运行” View 窗口中不会显示任何日志 - 即使从“最近的项目” View 打开应用程序后也是如此。
我联系了谷歌,但没有成功解决。我想知道这里是否有人遇到过这个问题,或者知道这可能是什么。
在模拟器上复制,但不是在新的空项目上。
编辑:添加日志 - 这些是使用 adb shell logcat
直接从设备中获取的命令。这些问题仅在应用程序已经运行时发生,并且在升级到 Android Studio 4.0 后开始发生。我的应用程序名称是 poscosecha
完整的包名是com.plantecuador.poscosecha
.该设备是具有 Android 7.0 (API 24) 的 RCA 10"平板电脑。该错误在具有相同 Android 版本的模拟器上重现。它不会发生 100% 的时间,但如果应用程序已经存在,则肯定会超过 75%运行。
有两种不同的错误情况。首先,应用程序移至后台。第二,应用程序完全关闭(不会出现在后台任务中)。如果运行之间有变化,第一种情况似乎发生得更频繁,而如果没有变化,第二种情况发生得更频繁。
第一种情况的Logcat:
https://pastebin.com/T1HFU9zb
第二种情况的Logcat:
https://pastebin.com/qJque7A7
编辑 2:添加 list
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.plantecuador.poscosecha">
<uses-permission android:name="android.permission.INTERNET" /> <!-- Bluetooth printer permissions -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false" />
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="false" /> <!-- Access fine & coarse location is used to determine the macaddress & bluetooth address -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:allowBackup">
<activity android:name=".SignInActivity" android:screenOrientation="sensorPortrait"
android:configChanges="keyboard|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" android:screenOrientation="sensorPortrait"
android:configChanges="keyboard|keyboardHidden"/>
</application>
</manifest>
最佳答案
android:screenOrientation="sensorPortrait"
可能导致问题。如果平板电脑处于横向模式,它可能会拒绝在没有用户交互的情况下进入纵向模式。
关于android - 从 Android Studio 运行时,为什么 Android 应用程序会在后台启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62301111/