简体   繁体   English

在Android中处理来电后,如何从以前的状态恢复活动?

[英]How to Resume Activity from Previous state after handling Incoming Call in Android?

I am creating app that download 4-5 images from server and display as gallery. 我正在创建从服务器下载4-5张图像并显示为图库的应用程序。 It working fine in normal condition. 在正常情况下,它工作正常。 but when there is incoming call or device is in sleep mode my activity load data from starting after onResume, i am not able to load data(Resume activity) from previous state of activity. 但是当有来电或设备处于睡眠模式时,我的活动从onResume之后开始加载数据,我无法从先前的活动状态加载数据(恢复活动)。

Is there any soulution? 有什么解决方案吗?

Thanks 谢谢

Check out Saving Cache Files . 签出“ 保存缓存文件” Save your images on pause and restore them on resume. 暂停保存图像,并在恢复时恢复它们。

You should probably cache the files, so it works like this, check if files already exist, if not download, when files exist load pictures, 您可能应该缓存文件,以便它像这样工作,检查文件是否已经存在,如果不下载,则在文件存在时加载图片,

http://developer.android.com/guide/topics/data/data-storage.html#ExternalCache http://developer.android.com/guide/topics/data/data-storage.html#ExternalCache

You should read how to handle runtime changes . 您应该阅读如何处理运行时更改

Basically, under some situations your Activity will be recreated. 基本上,在某些情况下,将重新创建您的活动。 To preserve state you can pass objects between old and new Activity, using onSaveInstanceState() in old activity and onRestoreInstanceState() in new activity. 要保留状态,您可以在旧活动和新活动之间传递对象,方法是在旧活动中使用onSaveInstanceState()在新活动中使用onRestoreInstanceState()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM