Home > Blockchain >  Opening up the previously viewed activity after killing the app KOTLIN
Opening up the previously viewed activity after killing the app KOTLIN

Time:09-11

In my app I have two activities, the first is the main activity/homepage that has buttons and the second displays an image. If the user is on the 2nd activity (ie. viewing an image) and they then close the app, killing it, how would I go about making it so that when I relaunch the app it shows the second activity with the image that the user was viewing?

I tried to add the following into the Manifest.xml

android:alwaysRetainTaskState="true"

So that the manifest looks as such:

<activity
    android:name=".SecondActivity"
    android:exported="true"
    android:alwaysRetainTaskState="true"

    /><activity
    android:name=".MainActivity"
    android:exported="true"
    
    >

However, this does not work and the Main activity always opens...

CodePudding user response:

one way is by using SharedPreferences to store the state of the user. If the user has viewed the Image , set the state to true.

And then in your MainActivity onCreate check the SharedPreference value, If it is true take the user to second screen.

  • Related