if you’re routing from fragment to another activity, you can put you data into the intent using the putExtra
and then receive in the activity using getExtra
.
Inside the fragment,
Intent profileActivityIntent = new Intent(context,ProfileActivity.class);
profileActivityIntent.putExtra("dataKey",data);
startActivity(profileActivityIntent);
And then inside the ProfileActivity’s onCreate
method,
//assuming that data is a string
String dataFromFragment = getIntent().getStringExtra("dataKey");
Log.i("Data from fragment",dataFromFragment);
You are in no need of using the interface method. (If you have to route from one fragment to activity).
2
solved How to get data from fragment to another activity? (Not container activity) [duplicate]