I have a MainActivity and an Activity2. When I press a button on MainActivity, it starts the activity2 and on activity2 I have a button which when pressed i want to return to MainActivity without killing Activity2/releasing its resources(or hide the activity in background if possible). The button to launch activity2 is already achieved, but I don't know how can I hide the Activity2 on button press.
CodePudding user response:
Make your MainActivity
launchmode to singleInstance
in manifest
<activity
android:name=".MainActivity"
android:exported="false"
android:launchMode="singleInstance"/>
when clicking on button on Activity2 launch the MainActivity
again
findViewById<Button>(R.id.button).setOnClickListener {
val intent = Intent(this,MainActivity::class.java)
startActivity(intent)
}
CodePudding user response:
You can probably launch an intent that shows the home screen but not finish the Activity2