AhmadAssaf
AhmadAssaf

Reputation: 3664

Saving Android Activity state and Contents

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 click 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

Upvotes: 1

Views: 615

Answers (1)

Kiril Kirilov
Kiril Kirilov

Reputation: 11257

  • 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.

Upvotes: 3

Related Questions