开发者

Saving a activity view onpause or on backkey

I am creating a chat application for android. There are 2 activities PeoplesActivity and ChatActivity. The PeoplesActivity contains a list of users and onclicking of one user, ChatActivity, a new intent is created and I startActivity of ChatActivity.

Now my problem is, when a user presses backbutton from ChatActivity, he is braught back to peoplesactivity. But when I try to chat again with the user, I loose the initial chat thread. I tried creating a hash array of intents, and instead of creating a new intent on every user, I used the old intents. But yet, the chat log goes entirely missing.

My question is what would be the best method to save a changed state of a view as an object or something, so that when I start the activity again, I can get back the previous state of view.

Any help would be greatly appreciated. I am very new to android de开发者_高级运维velopment, this might be a very silly question.


I think you should save your log into persistent storage like database. In onCreate of ChatActivity you should retrieve the log from db, and on message post/receive you should store it to your db. Here's some info about Using Databases


You can use onSaveInstanceState to save the per-instance state of an Activity. The saved instance state will be provided in the onCreate method as parameter or you can get it back with the onRestoreInstanceState method. It will not be stored in a database so it will be lost if your application gets killed.

Have a look at this topic.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜