I have three fragment in an Activity C. they are behaving as tabs. I have to go from a fragment to a new Activity X. Now i want to come back to fragment from Activity X.
First, Override the back press to goto the activity where the fragments are :-
@Override
public void onBackPressed()
{
Intent intent = new Intent(CurrentActivity.this,ActivityYouLikeToGo.class);
intent.putExtra("Check",1);
startActivity(intent);
}
then goto the ActivityYouLikeToGo.java file and in onCreate do this:-
Intent intent = getIntent();
String s1 = intent.getStringExtra("Check");
if(s1.equals("1"))
{
s1 = "";
Fragment fragment = new YOURFRAMENTNAME();
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
}
}