Starting too many activities?

十年热恋 提交于 2019-12-07 18:05:09

问题


Hello is it possible to start like too many activities during the runtime of an application? I'm developing a schedule application where you can slide from day to day where each day is a new activity. Now I'm wondering if there is a limit somehow of the number of activities you should start max. As when sliding a bit around you are soon to about 20 activities which are active.

I know activities will be killed when other applications need memory but while testing and closing the application by pressing the home button with about 20 activities 'running' htc sense seems to be restarting like it was closed due to a lack of free memory. When I just have a few activities running this doesn't happen. (htc desire)

Can this be caused by starting too many activities? If so, is there a 'limit' of amount of activities you should start max?

Edit: I read somewhere that the twitter for android app is developed by google. But in that application you can have like unlimited number of activities running also.


回答1:


Even there is no such limitation in activity number, it is really a bad design to create too many activities. This is mainly because each activity is assigned specified minimum memory in VM and if it has IPC call, it will spend binder buffer.

We can re-design our app to reduce the number of activity. In your case, you can try to use one activity to show the day to day schedule. If it is hard to re-use, then we can close the previous activity as soon as possible to reduce the memory usage.




回答2:


While there is technically no hard limit, some devices will have problems with a larger number of activities. Some of the devices I did tests on started having problems around 8 activities or so.




回答3:


There is no such limit to my knowledge. Typically applications have like 5 open activities.

It is good programming practice to keep them to a lower number




回答4:


You can create as many activity in an application as you want, and how much is the device can keep running. There isn't any limit of this, but sometimes the devices can't run them. Usually you can create your application, with lower number activities, what's the better solution.



来源:https://stackoverflow.com/questions/6717473/starting-too-many-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!