-4

I have a class TestFragment which extends Fragment,from this Fragment I have started Activity1

and from Activity1 i have started Activity2,Now i am in Activity2 want to go to TestFragment

when a button inside Activity2 is clicked and i want to update the UI in TestFragment

String
  • 3,660
  • 10
  • 43
  • 66

3 Answers3

1

Call finish() if you want to go back to the caller activity. If you want to launch the activity which contains the fragment create an intent and launch the activity, something like startActivity(new Intent(this,youractivity.class));

Juan Cortés
  • 20,634
  • 8
  • 68
  • 91
1

Please write some code..Anyway if you want start another activity take a look here: http://developer.android.com/training/basics/firstapp/starting-activity.html onClick event you just put the intent for example Intent intent = new Intent(this, TestFragment.class);

Atlas91
  • 5,754
  • 17
  • 69
  • 141
  • How can i use startActivity as i want to go to TestFragment class – String May 20 '14 at 11:46
  • In which sense? just do something like: `Intent intent = new Intent(this, TestFragment.class);` and then `startActivity(intent);` – Atlas91 May 20 '14 at 11:47
1

you can clear the stack activity like this:

Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

by this code you will clear the stack and MainActivity will be opend. Hope this help you

Hamid Reza
  • 624
  • 7
  • 23