Android的 - 再利用活动实例 [英] Android - reuse Activity instance

查看:110
本文介绍了Android的 - 再利用活动实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动,主要和Rbrowser活动。在主要活动中显示的网址列表。当点击一个链接,Rbrowser活动启动。对于每个发射的setContentView(R.layout.rbrowser); 的onCreate 调用,这是缓慢的。

有没有什么好的做法重用活动的实例,只是重装Rbrowser的WebView中新的网址?

感谢


解决方案

您的问题不是这次的setContentView(),它不能使一个应用程序缓慢的,它是在微秒甚至在最慢的设备执行。你在加载内存部分的ArrayList或者HashMaps这样或任何其他笨重的变量在OnCreate()?如果是的话,也可以尝试在seprate线程或通过AsyncTask的。

I have two Activity, Main and Rbrowser Activity. In Main Activity a list of urls is shown. When a link is clicked, Rbrowser Activity is launched. For each launch setContentView(R.layout.rbrowser); is called from onCreate, which is slow.

Is there any good practice to reuse Activity's instance, and just reload Rbrowser's webview with new url?

Thanks

解决方案

Your problem is not the setContentView(), it can't make an app slow, it is executed in microseconds even on the slowest of devices. Are you loading some ArrayLists or HashMaps or any other bulky variable in the memory in the onCreate() ? If yes, try doing that in a seprate thread or via an AsyncTask.

这篇关于Android的 - 再利用活动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆