开发者

Saving Android Activity state and Contents

开发者 https://www.devze.com 2023-02-14 14:30 出处:网络
i am making a chatting application for android, now i create a new activity when a button is pressed to start the chatting. when i hit the back button the chats dialogs will disappear as the activity

i am making a chatting application for android, now i create a new activity when a button is pressed to start the chatting. when i hit the back button the chats dialogs will disappear as the activity is destroyed and on the button clic开发者_JS百科k a new activity is always created.

i want to save whats happening in my activity ( chatting history ) as well as the ability to open multiple chat windows, on click of button i can create new chat activity with the others not destroyed ..

I appreciate your help


  • Preferred way: Don't save the state of the chats in the current activity - bind some Service to the activities and load information from it.

  • Alternative: If this seems harsh for you, then you can use some Singleton to save all the information (which I not recommend, singletons are evil).

  • Second Alternative: In onPause of the activity, you can save the current state of the chat in SQLite database. And after that, in onResume you can load it again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号