Reputation: 782
So, (for example) let's say I have an activity with a method that sets the test of a TextView
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
setTextView();
}
public void setTextView() {
String myText = ...//fetches text from web server
tv.setText(myText);
}
}
If I go to another activity from this one, and the back button is pressed and I return to this activity, I want to be able to recall my setTextView()
method to update the text in the TextView. Is it possible to detect when a person "backs" into the activity? Thanks
Upvotes: 1
Views: 741
Reputation: 157437
In your case calling setTextView
from onResume
instead of onCreate
is enough, since when you press back the current activity is finished and the previous one is resumed.
Upvotes: 2