只有当我通过点击图标返回到我的应用时,它才会被销毁。如果我打开正在运行的应用程序列表并从那里返回,它将恢复正常运行。我在onDestroy()函数上设置了一个断点,因为我找不到在它之前被调用的任何代码。这是它被调用的线程:
onDestroy:500, CookActivity {com.mycompany.myapp}
performDestroy:6228, Activity {android.app}
callActivityOnDestroy:1157, Instrumentation {android.app}
performDestroyActivity:3898, ActivityThread {android.app}
handleDestroyActivity:3929, ActivityThread {android.app}
access$1400:160, ActivityThread {android.app}
handleMessage:1375, ActivityThread$H {android.app}
dispatchMessage:102, Handler {android.os}
loop:135, Looper {android.os}
main:5597, ActivityThread {android.app}
invoke:-1, Method {java.lang.reflect}
invoke:372, Method {java.lang.reflect}
run:984, ZygoteInit$MethodAndArgsCaller {com.android.internal.os}
main:779, ZygoteInit {com.android.internal.os}
似乎正在收到一些消息,希望从某处破坏我的活动。在Looper中,有一个名为msg的变量。这就是它的价值:
{ when=-5m57s667ms what=109 arg1=1 obj=android.os.BinderProxy@1433d777 target=android.app.ActivityThread$H }
有人知道这里发生了什么吗?如何像从运行的应用程序列表中选择应用程序一样正常地恢复我的应用程序?
编辑:根据要求,这是AndroidManifest.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/MainTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CookActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_cook"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity">
</activity>
<activity
android:name=".AlarmActivity"
android:excludeFromRecents="true"
android:showOnLockScreen="true"
android:showForAllUsers="true"
android:theme="@style/AlarmTheme">
</activity>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="org.eclipse.paho.android.service.MqttService" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
</manifest>
答案 0 :(得分:1)
您已在清单的 SingleTask 模式下将Main设置为活动状态,因此在启动其新实例时该活动将被销毁。 以下是有关SingleMode和启动模式的有趣文章:
https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en