I click on first Button multiple times which changes text Variable and once I press second button changed text Variable is shown with changed value.
But if I uncomment Text View text Variable gets reset once I press on the second Button.
Can someone explain what is going on?
Uncommented Text View (NOT WORKING)

package com.example.testcompose
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
//==========================================================
// MAIN ACTIVITY
//==========================================================
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
var text = remember{ "Hello " } //Remembered but not observed
var state by remember { mutableStateOf(0) } //Remembered and observed
Column {
Button({
text += "you "
Log.d("PRINT", text)
}) {
Text("Increase Text")
}
Button({state++}) { Text("Button was clicked $state times $text") }
//Text("Button was clicked $state times $text")
}
}
}
}
