I have a menu button that starts a new activity and when it's done the user presses a button and it writes data to an SQLite DB and finishes the activity. But the Fragment that it comes back to shows that information and it's not refreshing when the activity is finished. How can I make sure that the data is refreshed when I come back to the fragment?
I'm using startActivityForResult() and catching the result with the code below but I still do not get a refresh of the fragment
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == MainActivity.MYACTIVITY_REQUEST_CODE) && (resultCode == Activity.RESULT_OK))
adapter.notifyDataSetChanged();
}
One way to solve this is to use startActivityForResult(intent, MyStatusCode) and then capture the return by using something like:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == MyStatusCode) {
//Refresh the fragment here
}
}