I have followed this. I want to refresh the Activity
from Fragment
. I have back button in toolbar
for Fragment
to Activity
communication.
Here is my code for button listener and refresh the activity. I include this in fragment class:
final Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Handler().post(new Runnable() {
@Override
public void run()
{
Intent intent = getActivity().getIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_NO_ANIMATION);
getActivity().overridePendingTransition(0, 0);
getActivity().finish();
getActivity().overridePendingTransition(0, 0);
startActivity(intent);
}
});
}
});
This works fine, but it completly reload the app. What can be done here, so that I can avoid the reload operation and just refresh the activity?
Put this in your fragment
and put refreshMyData in your Activity
Let me know if not Working