My application launches AsyncTask, which downloads the file from the url. At the same time, it creates a status bar Notificationthat tells the user the percentage of completion of the download.
I am trying to configure the application to click on a notification. If the download is still in progress, I want to show DialogInterfacewhich asks them if they want to stop the download. Click "Yes" to stop the download.
The problem I am facing is that I'm not sure how to access my Async task from PendingIntentwhich I configured for notification. I can get DialogInterfaceto show easily enough, but I'm not sure how to show the action that occurs when the download should stop it.
I tried to create a Helper class that had access to the notification, as well as a File object that refers to the downloaded file, but I get an error that the object is not serializable (it implements Serializable). The helper class also included an element that would track the progress of loading, and this is what I would like to use to condition whether to show a dialog or not.
I was thinking about using the Brodcast action and receiver, but I'm not sure where to place the receiver. Will he go in a class that expands AsyncTask?
Any help would be greatly appreciated. This PendingIntentis attached to Notification. If you want to see more code, just ask.
public class DownloadNotificationActivity extends Activity {
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
Intent i = getIntent();
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick( DialogInterface dialog, int which ) {
switch ( which ) {
case DialogInterface.BUTTON_POSITIVE :
finish();
break;
case DialogInterface.BUTTON_NEGATIVE :
finish();
break;
}
}
};
if ( ) {
AlertDialog.Builder builder = new AlertDialog.Builder( this );
builder.setMessage( R.string.stop_download ).
setPositiveButton( R.string.yes, dialogClickListener ).
setNegativeButton( R.string.no, dialogClickListener ).show();
}
else {
}
}
}
, , ViewDetailActivity. DownloadFile, AsyncTask , . doInBackground() DownloadFile URL- URL-, Notification . PendingIntent Notification DownloadNotificationActivity ( ), , "" , AsyncTask.
, DownloadFile, , , DownloadFile DownloadNotificationActivity, .
!