-3

I have stored data with SharedPreferences from a Fragment. Now I want to pass that data from the Fragment to a RecyclerView in the main Activity.

How do I pass data from my Fragment back to my main Activity?

dbm
  • 10,376
  • 6
  • 44
  • 56
Sagar
  • 3
  • 1
  • Welcome to Stack Overflow At this site you are expected to try to write the code yourself. After doing more research, if you have a problem you can post **what you've tried with a clear explanation of what isn't working** and providing a Minimal, Complete, and Verifiable example. I suggest reading [How to Ask](https://stackoverflow.com/help/how-to-ask) a good question and the [perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour](https://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/6676466). – Vishal Chhodwani Jul 27 '17 at 05:38

2 Answers2

0

Once you have stored the data that you want to send to the Main Activity, You can load it in the Main Activity using:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME,MODE_PRIVATE); 
String restoredText = prefs.getString("text", null);
0

Once you have stored data in shared preference from fragment use interface to refresh data of activty.

ref.: Passing Data Between Fragments to Activity