Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (downloading)
Viewing all articles
Browse latest Browse all 3

Activity Indicator while downloading JSON and saving in database

$
0
0

Hi, after check login, I'm downloading the info for the day in a JSON and saving all in local database, it works fine but I need to show an activity indicator while is processing the info. Here is the code where call to download all the info.

onload: function(e) {
    var activity=Ti.UI.createActivityIndicator({message:'Loading..',}).show();
 
    Ti.App.Properties.setString('username',txtUsername.value);
    Ti.App.Properties.setString('password',txtPassword.value);
 
    database.saveUser(txtUsername.value,txtPassword.value);
    database.createDatabase();
 
    restClient.downloadAll();                                           
    mainMenu=new mainMenu().open();
},
And here is the part of the downloadAll function
exports.downloadAll=function(){
    var url = URL_GET_ALL_INFORMATION;
    xhr = Ti.Network.createHTTPClient({timeout:120000});
    xhr.onload= function(e) {
        var data = JSON.parse(this.responseText).results;
        var products=data.product;
                try{
                for (var i = 0; i < products.length; i++){
                    databaseHandler.saveProduct(products[i].id_product,products[i].product_name,prod                ucts[i].product_description,products[i].product_capacity);
            }  
        }catch(e){}
 
        };
        xhr.onerror= function(e) {
            Ti.API.info('error'+e.error);
        };
    xhr.open("GET", url,true);
    xhr.setRequestHeader('Content-Type','application/json');
    xhr.setRequestHeader('login',Ti.App.Properties.getString('username'));
    xhr.setRequestHeader('password',Ti.App.Properties.getString('password'));
    xhr.send();
}

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>