Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid notification callback
    primarykey
    data
    text
    <p>I'm using this tutorial on AsyncTask with a task and a notification: <a href="https://eliasbland.wordpress.com/2011/03/11/an-example-of-how-to-run-a-background-task-and-report-progress-in-the-status-bar-using-asynctask-on-android/" rel="nofollow">https://eliasbland.wordpress.com/2011/03/11/an-example-of-how-to-run-a-background-task-and-report-progress-in-the-status-bar-using-asynctask-on-android/</a></p> <p>What I'm confused about is how to make a callback do something in the original class it was called from. Optimally, it would be great to have something like:</p> <pre><code>private class DownloaderTask extends AsyncTask { doInBackground() { ... download the file ... } onProgressUpdate, onPreExecute, etc. from the example, managing a notification. notificationClicked() { if (success) { //show file } else { cancel(true); } } </code></pre> <p>however, it seems the PendingIntent is made to open a new intent, not call a function on the class that opened it? Is there any way to do this?</p> <hr> <p>EDIT: Ok, I found out how to call the calling service from pendingintent:</p> <pre><code>Intent returnIntent = new Intent(_context,DownloadService.class); returnIntent.putExtra("url", _url); returnIntent.putExtra("name",_title); notificationIntent = PendingIntent.getService(_context, 0, returnIntent, 0); notification.setLatestEventInfo(_context, _title, _url, notificationIntent); </code></pre> <p>Since there is always only one service running, the DownloadService has an ArrayList of all its AsyncTasks, and onStart checks to see if one of them has the same url and title, if so, it calls the AsyncTask's method to cancel running item or do action on completed item.</p> <p>The count of the ArrayList is sent as the id of new DownloaderTasks, so each one will have a unique id to create its notification, but I noticed that sometimes when I select a notification in the status dropdown, it calls the DownloadService with the wrong url and title, almost like it's using another notification's ID? How can this be fixed?</p>
    singulars
    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.
 

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