Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

aakarshrestha
aakarshrestha
6,509 Points

Save the app state when the app is swiped left or right from the overview screen or recent apps list.

When I swipe the app, that I am logged into, from overview screen or recent apps list the app closes completely and I have to log in to the app again. How to prevent the log in process again and save the state of the application when accessed again?

For example: Open a facebook mobile app in your android phone. Go to the overview screen or recent apps list screen, you will see all the apps you have opened and among those app you will see facebook app as well. When you swipe the facebook app either left or right, app is no longer displayed in the overview screen or recent apps list. Now open the facebook app, you are already logged in and you state is saved.

How do I achieve the same behavior in my app?

Any suggest is highly appreciated!

Happy coding!

2 Answers

aakarshrestha
aakarshrestha
6,509 Points

I was able to get what i wanted, which is a user should be able to auto login to the app if the app is removed from the recent apps list.

I used sharedpreference for it and it works like a charm.

If anyone needs help or wants to know more about it, please comment and I will be more than happy to share my experience with you.

Happy coding!

Seth Kroger
Seth Kroger
56,413 Points

That's a topic that will take more than a forum post to answer but luckily Treehouse has a course on the Android Activity Lifecycle

aakarshrestha
aakarshrestha
6,509 Points

I have gone through the Android Activity Lifecycle and it does not have what I am looking for. Thanks for the reply though.