我的问题是,如果我在应用程序中打开任何活动,然后按主键按钮。然后重新打开应用程序,则会打开登录活动,而不是打开用户实际在其中的当前活动。
这仅在发布模式下发生。
应用清单文件
<?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.example.test">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:name="com.example.TestApp"
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"
android:networkSecurityConfig="@xml/network"
tools:node="merge">
<activity android:name=".pages.assitance.question.QuestionAnswerActivity" android:screenOrientation="portrait"></activity>
<activity android:name=".pages.tripdetails.TripDetailActivity" android:screenOrientation="portrait"/>
<activity android:name=".pages.profile.EditProfileActivity" android:screenOrientation="portrait"/>
<activity android:parentActivityName=".pages.main.MainActivity" android:name=".pages.QrActivity" android:screenOrientation="portrait"/>
<activity android:name=".pages.profile.ProfileActivity" android:screenOrientation="portrait"/>
<activity android:name=".pages.main.MainActivity" android:screenOrientation="portrait"/>
<activity android:name=".pages.login.LoginActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".core.location.TestService" />
<service
android:name=".TestService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
和gradle清单文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.test"
minSdkVersion 21
targetSdkVersion 28
versionCode 2
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
// minifyEnabled true
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':assi')
implementation project(':location')
implementation project(':notification')
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//butterknife
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
//picasso
implementation 'com.squareup.picasso:picasso:2.5.2'
//lottie animation
implementation 'com.airbnb.android:lottie:3.0.0'
//qr
implementation 'me.dm7.barcodescanner:zxing:1.9'
//location
implementation 'com.google.android.gms:play-services-location:16.0.0'
// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Retrofit and OkHttp
// OkHttp interceptors for logging
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.0.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
//room
implementation 'androidx.room:room-runtime:2.0.0-beta01'
annotationProcessor 'androidx.room:room-compiler:2.0.0-beta01'
// use kapt for Kotlin
//phone number validation
implementation 'com.googlecode.libphonenumber:libphonenumber:8.2.0'
//socket.io
implementation('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
//library for rating
implementation 'com.github.ome450901:SimpleRatingBar:1.4.2'
//firebase
implementation 'com.google.firebase:firebase-core:16.0.8'
//crashlytics
releaseImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.0'
//firebase push notification
implementation 'com.google.firebase:firebase-messaging:18.0.0'
}
repositories {
mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
如果我以调试或发布模式从android studio中运行该应用程序,则它可以正常运行
只有在我生成发行版APK时才会发生
有什么想法吗?
答案 0 :(得分:0)
如果您只想打开一次登录活动,并且在登录并重新打开应用程序时要打开家庭活动,则只需保存应用程序状态或将登录状态保存在共享首选项中即可。比较启动时的情况,然后决定应该在哪里进行首页活动或登录活动。
在登录活动中调用登录功能后获得成功时,请执行以下操作:
SharedPreferences pref = this.getSharedPreferences ("Login",0);
Editor editor = pref.Editor();
editor.putBoolean("login",true)
editor.commit();
在启动屏幕代码中执行此操作:
Boolean loggedIn = SplashScreen.this.getSharedPreferences("Login",0) .getBoolean
("login",false);
if(loggedIn) {
startActivity(new Intent(SplashScreen.this,HomeActivity.class));
finish();
} else {
startActivity(new Intent(SplashScreen.this,LoginActivity.class));
finish();
}
答案 1 :(得分:-1)
当您按下主屏幕按钮时,您的应用程序将进入后台状态。在这种状态下,您的应用可能会被操作系统杀死,也可能不会被操作系统杀死(官方资料进行了详细说明)。您应该假设它总是如此。在这种情况下,当您导航回您的应用程序时,您的应用程序将表现为首次运行。
为解决这个问题,一种常见的方法是创建一个“控制器”活动(称为Splash)并将其设置为启动器。该活动包含决策代码,可将用户导航到适当的活动。