You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Davide Maestroni (JIRA)" <ji...@apache.org> on 2013/05/02 17:20:15 UTC

[jira] [Commented] (CB-3064) The preferences are read only the very first time the application runs

    [ https://issues.apache.org/jira/browse/CB-3064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13647617#comment-13647617 ] 

Davide Maestroni commented on CB-3064:
--------------------------------------

I'm sorry, you are right in saying a didn't provide enough details. So let me try to do it now.

Actually, what I see is not what you describe: the activity lifecycle is respected, and I can see from the logs that both onDestroy and then onCreate methods are successfully called. The problem seems to be related to the fact that the Config class implements a singleton, so that, stepping line by line with the debugger during the second call to onCreate, after the application re-start, and printing the value of Config.self I found out it was not null! Thus causing the parsing of the config.xml file to be skipped.
It looks like the Config object is retained during the application stop and re-start, and that is the root cause of the issue. To prove it is the fact that, even if the config.xml file is not parsed again, the settings stored as members of the Config instance, like the whitelisted URLs or the log level, are retained as well, while settings like the background color, which are stored in the bundle extras, are simply lost.

Since the self attribute of the Config class is private I cannot reset it to null, so my workaround is to just explicitly parse the config.xml file and put the settings values in the bundle extras every time the onCreate function gets called.
                
> The preferences are read only the very first time the application runs 
> -----------------------------------------------------------------------
>
>                 Key: CB-3064
>                 URL: https://issues.apache.org/jira/browse/CB-3064
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.5.0, 2.6.0
>         Environment: All Android versions and devices
>            Reporter: Davide Maestroni
>            Assignee: Joe Bowser
>
> The preferences in the config.xml file are not read again if application exits and then restarts.
> A simple test is to set the background color to GREEN (-16711936 or [0xff00ff00]) and use an html page with transparent background. 
> The first time it is run, the application correctly displays a green background but then, after exiting by pressing the back or home button, and re-running it, the background stays black.
> Forcing the application thread to stop from the Android settings menu seems to cause the preferences file to be read again.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira