0

I found that to refresh an activity you do, finish(); startActivity(getIntent());

However this is possible only if my present class extends Activity class. But my present class extends Fragment class, so how to I refresh it?.

I tried to pass the object of Intent from my MainActivity.java to this class via the constructor but then I was not able to call finish() that way.

MyWay
  • 1,011
  • 2
  • 14
  • 35
PKBEST
  • 321
  • 2
  • 13

2 Answers2

0

Try use FragmentTransaction. Replace a fragment with itself, what does work for me is using detach and attach:

getSupportFragmentManager() .beginTransaction() .detach(fragment) .attach(fragment) .commit();

Victor Gomes
  • 463
  • 6
  • 15
0

You have to pass this object(Context) of the Activity to the class and call finish() + startActivity() on that. From MainActivity.java pass this object and hold in your class as an Activity object and call finish() + startActivity() methods on this.

bofredo
  • 2,348
  • 6
  • 32
  • 51