TargetSDK33、minSDK24下MainActivity onCreate被调用两次问题求助
求助:首次安装应用后主启动Activity的onCreate被调用两次
我正在排查首次安装应用时主启动Activity的onCreate被调用两次的问题。已经创建了一个空Activity并添加了生命周期日志,尝试设置launchMode为singleTop和singleInstance但均无效。以下是相关代码及日志截图,恳请告知可能的原因。
Activity代码
package com.ninja.myapplications; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity { String TAG = "Debug"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i(TAG, "onCreate"); } @Override protected void onDestroy() { super.onDestroy(); Log.i(TAG,"onDestroy"); } @Override protected void onStop() { super.onStop(); Log.i(TAG,"onStop"); } @Override protected void onResume() { super.onResume(); Log.i(TAG,"onResume"); } @Override protected void onPause() { super.onPause(); Log.i(TAG,"onPause"); } }
Manifest.xml代码
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyApplications" tools:targetApi="31"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
build.gradle代码
plugins { id 'com.android.application' } android { namespace 'com.ninja.myapplications' compileSdk 33 defaultConfig { applicationId "com.ninja.myapplications" minSdk 24 targetSdk 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
日志输出

内容的提问来源于stack exchange,提问作者kavie
相关产品推荐
相关产品推荐

