I am new to android studio. I am building an application using esp8266 to toggle pins the ip address and the port number are in the second activity I used SharedPreferences to save data in the second activity so that they remain saved every time I close the app. Then I send this data to the MainActivity. I need to save this data because I need to use it in the MainActivity just like the second activity. I want it to but I don't know. Can any body help me please. Thanks
-
Possible duplicate of [How to use SharedPreferences in Android to store, fetch and edit values](http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values) – OneCricketeer Apr 30 '16 at 17:46
3 Answers
Your question is not clear if you put the data in shared prefs so read it from the other activity if you dont know haw to read from shared prefs here answer to do so How to use SharedPreferences in Android to store, fetch and edit values

- 1
- 1

- 1,109
- 8
- 18
I am not able to get your question , but what I understand from your question is , you are saving the data in shared preferences in the second activity and you want to access the same data in the MainActivity , since you will be saving the data using a key , you can fetch the same data using the same key in the MainActivity , for more details you can go through - http://developer.android.com/training/basics/data-storage/shared-preferences.html

- 401
- 1
- 4
- 12
Your question is not clear but i think this will help you http://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
To get Values from another activity. For example your shared preferences class name is Session then to get values:
Session session=new Session();
HashMap<String, String> user = session.getUserDetails();
String user_name=user.get(Session.KEY_NAME);
And now you can use user_name anywhere in activity

- 73
- 7