Note that there are some explanatory texts on larger screens.

plurals
  1. POSpawning a thread from an Activity in Android need advice on re-factoring
    primarykey
    data
    text
    <p>I have developed a file downloader which shows progress in the notification bar (Like Android Market Downloads). I have based my work <a href="https://github.com/nheid/unitedcoders-android/blob/master/src/com/unitedcoders/android/examples/download/DownloadProgress.java" rel="nofollow">on this example</a>. </p> <p>In My activity i start a download thread like</p> <pre><code>private void startDownload() { DownLoadFileHandler filedownLoad = new DownLoadFileHandler(this, getIntent().getDataString(),mDirectory,mFileName.getText().toString(),mHandler); filedownLoad.downloadfile(); finish(); //End the Spawning activity } </code></pre> <p>Run function in the download thread </p> <pre><code>public void run() { try { //do some pre processing setupNotification(); //while downloading keep updating notification with flag FLAG_ONGOING_EVENT Once Download is complete change the flag FLAG_AUTO_CANCEL and update for the final time } catch (Exception e) { if(notificationManager != null) notificationManager.cancel(DOWNLOAD_NOTIFICATION); } } </code></pre> <p>Now I noticed that while downloading files if i make/receive a call for a substantial amount of time (on a 2g network which does not support calling and net at the same time), the thread dies, disappears and my notification for the incomplete downloads remain stuck as an on going notification in the notification bar which can only be cleared on rebooting.</p> <p>I feel that i have down spawning a thread from an Activity(the only activity at that time in the application) and then calling finish on it is a mistake on my part. So i need to re factor the code.</p> <p>My questions what exactly am I doing wrong in this approach (as download seems to work with notification updates if there is no call)</p> <p>What should be the best approach to address the issue as outlined above ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload