Android SDK equivlent for viewWillAppear (iOS)?

我怕爱的太早我们不能终老 提交于 2019-12-04 02:19:54
SiPe

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.

Anasthase

You can also create an OnSharedPreferenceChangeListener. Register it in your Activity.onCreate() with PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(). Also unregister it in Activity.onDestroy() with PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener().

Chris

You could also start your Settings activity with startActivityForResult and then implement an onActivityResult method in your Main activity: StartingActivities

the best solution I found is to override onVisibilityChanged

@Override
protected void onVisibilityChanged(View changedView, int visibility){
    super.onVisibilityChanged(changedView, visibility);
    if(visibility==VISIBLE ){
        Log.v("View will appear", "");  
    }
    else{
        Log.v("View will disappear", "");   
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!