how do I restart an activity in android?
This has been posted before:
Intent intent = getIntent();
finish();
startActivity(intent);
As of API level 11, you can also just call an activity's recreate()
method. Not only is this cleaner because it is less code, it avoids issues that may arise if your activity was launched by an implicit intent.
Reload activity in Android
You can Simply use
finish();
startActivity(getIntent());
to refresh an Activity
from within itself.
Restart Activity onPostExecute
You can Simply use
startActivity(getIntent());
finish();
to refresh an Activity from within itself.
Alternatively you can call recreate()
to refresh the activity.
how to restart activity from fragment?
Your question is not clear. I think FragmentA is a DialogFragment. At least i assume it.
You can override onDestroy method in FragmentA and write
((MyActivity)getActivity()).refreshUI();
We basicly, casted activity instance to our activity for letting us call our method that you can refresh ui.
An dirty way is,
You can also write
Intent intent = new Intent(getContext, MyActivity.class);
intent.setFlag(Intent.CLEAR_TASK);
startActivity(intent);
By this way, we started our activity again and killed the one which is in backstack. I assume your datas is hold from another class which like singleton. Otherwise you lose them or you can use first method.
Good luck there.
Related Topics
Android, Detect When Other Apps Are Launched
How to Have Android Service Communicate With Activity
Android How to Adjust Layout in Full Screen Mode When Softkeyboard Is Visible
How to Resize a Bitmap in Android
How to Support Different Screen Size in Android
Horizontalscrollview Within Scrollview Touch Handling
Detect Network Connection Type on Android
Determine If the Device Is a Smartphone or Tablet
Ioexception: Read Failed, Socket Might Closed - Bluetooth on Android 4.3
How to Support Arabic Text in Android
How to Create Our Own Listener Interface in Android
Programmatically Register a Broadcast Receiver
How to Retrieve the Dimensions of a View
What Is the List of Supported Languages/Locales on Android
How to Implement Onbackpressed() in Fragments
How to Create a Custom-Shaped Bitmap Marker With Android Map API V2