Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SDK equivlent for viewWillAppear (iOS)?

Situation

I have a fairly simple app with 2 "layouts" using SharedPreferences.

  • Main.xml
  • Settings.xml

Main has a textView that uses getString from SharedPreferences. Also a button to open Settings.

Settings has a spinner and a button to save to SharedPreferences.


The textView gets updated when the App loads as I am calling setText() inside onCreate(Bundle savedInstanceState)

Problem

When I open Settings and update the SharedPreferences, I use the Back button to get back to Main.

Since I am calling setText() inside onCreate() the textView does not update again until I exit the app and open the app again to main.

What method do I need to use to update the textView after coming back from Settings?

My request is similar to the viewWillAppear() for iOS.

like image 864
14 revs, 2 users 97% Avatar asked Dec 07 '11 18:12

14 revs, 2 users 97%


1 Answers

onCreate() is only called once when the activity first starts. If you want to update text whenever the activity becomes active you can use onResume() instead. More information on the Activity lifecycle can be found here.

like image 195
SiPe Avatar answered Oct 17 '22 04:10

SiPe