How to persist a View across Activities in Android

前端 未结 5 1413
遇见更好的自我
遇见更好的自我 2021-02-03 15:43

I\'m working on an Android application and I\'d like to maintain a top-bar of sorts in most of my Activities, as per the Twitter and Facebook applications. How is this done? I\'

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-03 16:13

    I think your best bet would be to define a custom view and re-use it wherever needed. Though I don't think you'd technically have the same instance across activities, you can produce the illusion by updating it whenever necessary. (Perhaps in the onResume() method of each activity.) To save the data you can use SharedPreferences, which do persist across activities in an application, and even between instances of the particular application.

提交回复
热议问题