How to use onResume()?

后端 未结 8 1805
慢半拍i
慢半拍i 2020-12-04 17:21

Can anyone give me an example that uses onResume() in Android?

Also, if I want to restart the activity at the end of the execution of another, which met

8条回答
  •  悲哀的现实
    2020-12-04 17:49

    Most of the previous answers do a good job explaining how, why, and when to use onResume() but I would like to add something about re-creating your Activity.

    I want to know if I want to restart the activity at the end of exectuion of an other what method is executed onCreate() or onResume()

    The answer is onCreate() However, when deciding to actually re-create it, you should ask yourself how much of the Activity needs to be re-created. If it is data in an adapter, say for a list, then you can call notifyDataChanged() on the adapter to repopulate the adapter and not have to redraw everything.

    Also, if you just need to update certain views but not all then it may be more efficient to call invalidate() on the view(s) that need updated. This will only redraw those views and possibly allow your application to run more smoothly. I hope this can help you.

提交回复
热议问题