Android layout doesn't "refresh" until I start a new activity

时间:2015-07-13 21:01:54

标签: android android-activity layout

I have this problem. I wrote a program and I have this code in the MainActivity class:

    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.

1 个答案:

答案 0 :(得分:0)

您可以在第一个活动中使用onResume()在第二个活动完成时更新您的用户界面。

或者使用startActivityForResult开始第二个活动,当第二个活动结束时,它将为您调用onActivityResult