简体   繁体   中英

How to create Android Service Without interval in Appcelerator/titanium Android?

I want to create a service in appcelerator android where it starts when i click a download button and stops only if download is interrupted/fails or network is not present.

How can i achieve it? I have referred this article http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Service

I am following this http://docs.appcelerator.com/platform/latest/#!/guide/File_Uploads_and_Downloads for downloading content (videos)

The other problem i face is ,i can't access the UI or the UI becomes almost non responsive, though i can scroll up and down. when download is in progress on android. This is what the UI looks like and i call a function on click of download button.

NOTE: Each element,light gray rectangle is like an accordian control, which toggles(expands and retracts) on click.

在此处输入图片说明

I have written a code like this in a videoDownloader.js file

 function downloadVideos(video_download_url){
       var xhr = Titanium.Network.createHTTPClient({
        onload: function() {
            // first, grab a "handle" to the file where you'll store the downloaded data
            var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'video.mp4');
            f.write(this.responseData); // write to the file

            timeout: 10000
    });
    xhr.open('GET',video_download_url);
    xhr.send();
    }

您可能需要研究这个模块 ,它可以为您处理所有事情。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM