【发布时间】:2020-09-29 17:21:14
【问题描述】:
在 Android Studio 4.0 中按“运行”时,有时我的应用会在设备(运行 Android 7.0 的平板电脑)的后台启动。这意味着我必须转到设备上的“最近的项目”视图,然后按那里的应用程序才能打开。应用程序无法正常在前台启动。
发生这种情况时,Android Studio 的“运行”视图窗口中不会显示任何日志 - 即使从“最近的项目”视图打开应用后也是如此。
我联系了 Google,但没有成功解决。我想知道这里是否有人遇到过这个问题,或者知道这可能是什么。
在模拟器上复制,而不是在新的空项目上。
编辑:添加日志 - 这些是使用 adb shell logcat 命令直接从设备中获取的。这些问题仅在应用程序已经运行时发生,并且在升级到 Android Studio 4.0 后开始发生。我的应用程序的名称是poscosecha,完整的包名称是com.plantecuador.poscosecha。该设备是具有 Android 7.0 (API 24) 的 RCA 10" 平板电脑。该错误在具有相同 Android 版本的模拟器上重现。它不会发生 100% 的时间,但如果应用程序已经存在,则肯定会超过 75%正在运行。
有两种不同的错误情况。首先,应用程序移至后台。第二,应用程序完全关闭(不会出现在后台任务中)。如果运行之间有变化,第一种情况似乎发生得更频繁,而如果没有变化,则第二种情况发生得更频繁。
第一种情况的Logcat:
第二种情况的Logcat:
编辑 2:添加清单
<?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>
【问题讨论】:
-
以防万一,尝试进入 AVD 列表,选择行为不端的模拟器,擦除数据。
-
这种情况每次都会发生吗?你在哪里检查日志?在运行窗口或 logcat 窗口中。你的 logcat 也显示日志吗??
-
我已经经历同样的问题好几个月了,Galaxy S10+ 和 AS 4.0 也是如此。
-
"应用程序完全关闭" => "它死了"。当您点击
Run时,它首先必须停止应用程序(如果正在运行),然后再部署新版本,然后再启动它。如果关闭超时,它将不会启动。 -
我有时也会遇到同样的问题
标签: android android-studio android-studio-4.0