I have this problem. I wrote a program and I have this code in the MainActivity class:
我有这个问题。我写了一个程序,我在MainActivity类中有这个代码:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent activity = new Intent(MainActivity.this, AnotherActivity.class);
startActivity(activity);
output.setText(object.toString());
}
});
In AnotherActivity I modify the object and after that activity ends (with finish()) i want to "refresh" the textView of the MainActivity. At the end of AnotherActivity the object is actually modified, but the text is not refreshed. If I click again on button, before new Activity is started (with his layout) the text is refreshed as it should, and if I close the AnotherActivity layout, the text is well refreshed. But if I don't click again that button, the text remains the old one. How can I do? Sorry for bad English or bad explanation.
在AnotherActivity中我修改了对象,在活动结束后(使用finish())我想“刷新”MainActivity的textView。在AnotherActivity结束时,实际修改了对象,但文本未刷新。如果我再次单击按钮,则在启动新活动(使用其布局)之前,文本将按原样刷新,如果我关闭AnotherActivity布局,则文本会得到很好的刷新。但是如果我不再点击那个按钮,文本仍然是旧的。我能怎么做?抱歉英文不好或解释不好。
1 个解决方案
#1
0
You can use onResume()
in the first activity to update your UI when the second activity is finished.
您可以在第一个活动中使用onResume()来在第二个活动完成时更新UI。
Either that or start the second activity with startActivityForResult which will call onActivityResult for you when the second activity is finished.
或者用startActivityForResult开始第二个活动,当第二个活动结束时,它将为你调用onActivityResult。
#1
0
You can use onResume()
in the first activity to update your UI when the second activity is finished.
您可以在第一个活动中使用onResume()来在第二个活动完成时更新UI。
Either that or start the second activity with startActivityForResult which will call onActivityResult for you when the second activity is finished.
或者用startActivityForResult开始第二个活动,当第二个活动结束时,它将为你调用onActivityResult。