I need to reload an activity from another activity in android application. That 2nd activity is a dialog window, and based on the dialog window base activity should refresh the contents. (By click button of dialog activity)
-
3Are you using `startActivityForResult` in the first Activity? – OneCricketeer May 03 '17 at 05:24
-
yes.I used startActivityForResult to initialize second activity – kAsdh May 03 '17 at 05:42
-
1Ok, then you just need to implement `onActivityResult` to do the "refresh" things – OneCricketeer May 03 '17 at 05:43
-
Post your code here please – Bhavnik May 03 '17 at 06:19
3 Answers
Reload your activity.
context.startActivity(context.getIntent());
context.finish();

- 35,739
- 32
- 114
- 161

- 997
- 1
- 8
- 9
Consider A is an activity you want to reload and B is another activity.
In this case, just call finish() when you are moving from A to B. When you call A from B it will load the activity A again.

- 3,944
- 1
- 17
- 33
Dialog Window and activity is completely deferent things.
It is possible to refresh First Activity from it's dialog. You can do it using interface.
Here is simple solution. In your First Activity implements a Interface name IRefreshInteface
. It's definition is like bellow:
public interface IRefreshInteface(){
public void doRefreshValue(String commandValue);
}
Now if you implement IRefreshInteface in your activity you will get method doRefreshValue(String commandValue)
and write refresh code here.
@Override
void doRefreshValue(String commandValue){
// Write refresh code here
}
Now in your dialog you have Context of your Activity. Using that context object you can call this doRefreshValue(String commandValue)
method easily. Here is the sample code :
public AlertDialog displayMessage(Context context, String title, String message){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
LayoutInflater inflater = LayoutInflater.from(context);
final View v = inflater.inflate(R.layout.custom_view, null);
builder.setView(v);
shipText = (EditText)v.findViewById(R.id.shipNameEditText);
scientistNameText = (EditText)v.findViewById(R.id.scientistEditText);
scientistEmailText = (EditText)v.findViewById(R.id.emailEditText);
volumeText = (EditText)v.findViewById(R.id.volumeEditText);
colourText = (EditText)v.findViewById(R.id.colourEditText);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((IRefreshInteface) context).doRefreshValue("YOUR_COMMAND");
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog= builder.create();
dialog.show();
Button tb = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
tb.setOnClickListener(new CustomListener(dialog));
return dialog;
}
here, pass Context of Activity todisplayMessage()
method and call activity method doRefreshValue
using this way:
((IRefreshInteface) context).doRefreshValue("YOUR_COMMAND");
For more info visit here and here
Hope this will solve your problem. Sorry for bad english :)

- 1
- 1

- 6,749
- 3
- 61
- 87