Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15434] Android: Cookies are not preserved after closing the app

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, cookies, httpclient
ReporterFokke Zandbergen
AssigneeUnknown
Created2013-09-05T11:12:49.000+0000
Updated2020-08-18T20:42:48.000+0000

Description

On iOS any cookies set in HTTPClient sessions are kept until you or the server clears them. On Android though, they are cleared when you exit the app (not to the background, but really close it).

To reproduce

Create new app: titanium create -p ios,android -n testCookies -d . --id test.cookies

In app.js use:

    Ti.API.debug('I was just opened, not resumed');

    var w = Ti.UI.createWindow({backgroundColor:'white'});
    var b = Ti.UI.createButton({top: 100, title:'Request'});
    var l = Ti.UI.createLabel({top: 200});

    b.addEventListener('click', function () {
        var client = Ti.Network.createHTTPClient({
            onload: function(e) {
                l.setText(this.responseText);
            }
        });
        client.open('GET', 'http://dev.fokkezb.nl/cookie.php');
        client.send();
    });

    w.add(b);
    w.add(l);

    w.open();
    

Run the app on both iOS and Android

Click the *Request* button several times

Confirm that under the button the server response is a incrementing number

Force close the app

Open the app again and click the *Request* button

You'll see that on iOS the number picks up where it was, but on Android is starts at 1 again

Server code

The PHP code on the server is really simple:
<?
session_start();
echo $_SESSION['count'] = (int) $_SESSION['count'] + 1;
?>

Comments

  1. Mauro Parra-Miranda 2013-09-09

    How did you close / killed the app in iOS?
  2. Fokke Zandbergen 2013-09-10

    I closed the app on iOS (7) by:

    Singletap on the home button to move it to background.

    Doubletap on the home button to bring up the new multitasking screen.

    Swipe the app screen up to close it.

    I've added a log call to the example code above so in the logs you can tell it's not resuming, but actually opening the app from scratch, still preserving the session and thus cookie.
  3. jithinpv 2014-09-26

    Issue reproduces Titanium SDK version 3.4.0 master, 3.1.2.GA Titanium Studio, build: 3.3.0.201407100905 Titanium Command-Line Interface CLI version 3.3.0, Android device : Motorola Moto G, Android version : 4.4.4
  4. Osian Evans 2016-10-13

    Any news on this issue?
  5. Nikos Poulios 2017-06-29

    I noticed that android get/addSystemCookie is not working on Android 6.1.0.GA. After some testing I found out that those functions were not working on previous versions either (5.4.1/6.0.4) but it was noticed now in 6.1.0.GA, because I suppose that cookies were auto synced with the webview and in 6.1.0.GA cookies are not available after you restart the app I also added this comment on TIMOB-20075. I see 3 related tickets all going back to older versions, I am not sure if this should be a new ticket for 6.1.0.GA

JSON Source