I am making an android app with kotlin.
When linking Google account, I want to return to the first page after initializing by erasing all application information using clearApplicationUserData () when logging out.
It seems to be a specification that the application crashes after executing it, but is there a way to make the first transition by restarting or screen transition?
I looked it up, but I was in trouble because there were many English sites.

Corresponding source code
// Log out button
                signOutButton.setOnClickListener {
                    Firebase.auth.signOut ()
                    mGoogleSignInClient? .SignOut ()
                    mAuth? .signOut ()
                    // Erase all application data
                    val am = ContextCompat.getSystemService (this, ActivityManager :: class.java)
                    am? .clearApplicationUserData ()
                    // Return to the original page (cannot return)
                    val i = baseContext.packageManager
                        .getLaunchIntentForPackage (baseContext.packageName)
                    i !!. addFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP)
                    startActivity (i)
                    finish ()
Supplementary information (FW/tool version, etc.)

kitkat and above

  • Answer # 1

    Although deprecated, I was able to log out after using Google Api Client forcibly.

          // Add for logout
            mGoogleApiClient = GoogleApiClient.Builder (this)
                .enableAutoManage (
                ) {}
                .addApi (Auth.GOOGLE_SIGN_IN_API, gso)
                .build ()

  • Answer # 2

    Thinking normally, once the app is closed, you can't touch it after that.
    Please give up because it is impossible.