而应用程序正在运行我的Andr​​oid应用的单被重新初始化 [英] My Android app's singleton gets re-initialized while app is running

查看:246
本文介绍了而应用程序正在运行我的Andr​​oid应用的单被重新初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了2-3天到我的问题的解决方案,但我还没有发现任何人谁也有类似的问题。基本上,我的应用程序是一个网站的手机版,所以我不得不临时存储不同的帐户的信息,所以我用了一个signleton类,称之为用户。然而,尽管通过一定的2活动navigationg(在我有一个可扩展的列表和其他列表视图一样,你有车(1活动)从店(第二活动)元素来替代其空出的空间,所以你从一个其他的,反之亦然几次)去。
所以,虽然前进和backwork(通过意向书()),突然单身被重新初始化使应用程序崩溃即可。奇怪的事实是,我不要在logcat中得到任何错误,它只是记录在某一点上,singlotn调用它的init()方法,使得应用immidiatley之后崩溃。另一个奇怪的事情是,我实现这个东西,它的工作没有室内用的问题第一次,但现在我已经实现了其他一些活动,并添加了所有的图形元素(活动和列表元素,许多可绘等背景)我搞定这个问题(仅做操作之前说的)。
(我不知道这个东西是相关的),我的应用程序使用由J.范士丹(这是在几个acitivities impemented,那个以扩展列表,如)滑动菜单和ActionBarSherlock(但我使用自定义的操作栏,所以我吹我自己的动作条的布局)。每个活动都有其滑动菜单,创建的每个时间的onCreate()每个活动的方法。

I searched for 2-3 days a solution to my problem, but i haven't found anyone who had a similar problem. Basically, my app is the "mobile version" of a web site, so I have to store temporally different account's informations, so I used a signleton class, call it "user". Yet while navigationg through certain 2 activities (in one I have an expandable list and in the the other a listview , like you have a cart (1st activity) to substitute its empty spaces with elements from the "shop" (2nd activity); so you go from one the other and viceversa several times). So, while going forward and backwork (via Intent()), suddenly the singleton gets re-initialized making the app crashing. The strange fact is that I do not get any error on the logcat, it only logs at a certain point that the singlotn call its init() method, making the app crashing immidiatley after. Another strange thing is that the first time that I implement this stuff it worked wiht no problem, yet now that I've implemented several other activities and added all the graphic elements (backgrounds for activities and list elements, many drawables, etc.) I get this problem (only doing the operations said before). (I don't know if this thing is relevant) My app uses the sliding menu by J. Feinstein (which is impemented in several acitivities, the one with the expandable list, e.g.) and the ActionBarSherlock (yet I use a custom action bar, so I inflate my own actionBar layout). Each activity has its sliding menu, created every time on onCreate() method of each activity.

或code的每一个部分日志,你需要帮我,只问事件和我把它放在这里。

Every part of code or log events that you need to help me, just ask and I'll put it here.

非常感谢你提前为您的帮助,我真的坚持了这个问题。

Thank you very much in advance for your help, I'm really stuck with this problem.

推荐答案

我猜你想有一些会话的用户。

I guess you want to have some "session" user.

我不知道确切的问题,但据我所知Android系统可能会破坏静态数据时,它是低在内存中。

I don't know the exact issue, but afaik the Android system may destroy static data when it is low in memory.

你可以做的就是存储一些值(用户,时间戳)以preference值或持久性数据(文件,DB)。另一种方法是,当然,以从一个活动所需的用户数据传递到另一个

What you could do is store some values (user, timestamp) as Preference-values or as persistent data (file, db). Another way is of course to pass the required user data from one activity to another.

这篇关于而应用程序正在运行我的Andr​​oid应用的单被重新初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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