diff --git a/app/src/main/java/com/ivyclub/contact/ui/main/MainActivity.kt b/app/src/main/java/com/ivyclub/contact/ui/main/MainActivity.kt index 7df44f91..a79c9980 100644 --- a/app/src/main/java/com/ivyclub/contact/ui/main/MainActivity.kt +++ b/app/src/main/java/com/ivyclub/contact/ui/main/MainActivity.kt @@ -23,6 +23,9 @@ import com.ivyclub.contact.ui.password.PasswordActivity import com.ivyclub.contact.util.BaseActivity import com.ivyclub.contact.util.hideKeyboard import dagger.hilt.android.AndroidEntryPoint +import android.app.ActivityManager +import android.content.Context +import android.os.Build @AndroidEntryPoint class MainActivity : BaseActivity(R.layout.activity_main) { @@ -54,7 +57,16 @@ class MainActivity : BaseActivity(R.layout.activity_main) { override fun onStop() { super.onStop() - viewModel.lock() + val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + val curComponentInfoInString = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + activityManager.appTasks[0].taskInfo.topActivity.toString() + } else { + activityManager.getRunningTasks(1)[0].topActivity.toString() + } + + if ("OssLicensesMenuActivity" !in curComponentInfoInString) { + viewModel.lock() + } } private fun checkFromNotification() {