I’m using a AsyncTask that downloads an apk file and then install it at post execute method.
Pre Execute
{
Get a notification variable from shared preference and adds +1 to it
Create a new notification based on this variable
}
Do In Background
{
Update this notification based on its ID -1 (to refer to initial notification ID)
}
Post Execute
{
Update this notification based on its ID -1 (to refer to initial notification ID)
}
At the same time when this thread is running (example downloading a very large file over network) I would allow user to start another download. In this case I want to show 2 notifications instead of reusing the same notification ID. What is the best way to have 2 unique notification ID that does not conflict when i’m referring its Notification ID in Do In Background and Post Execute thread? Thanks
Found the solution after taking a nap to rest. Must have been too tired to figure it out
I’ve placed a local variable
private int notification_IDinside eachAsyncTaskAfter creating the notification, insert into shared preference (Notification_ID + 1)
Do In Background and Post Execute still uses this private variable when updating this notification
When a new
AsyncTaskthread is started, it will first read from shared preference which will be a new value (assuming first was 0, second would be 0+1 = 1) Then when its Do In Background and Post Execute try to access itsnotification_IDit will be accessing its own private variable with the value 1 hence will not conflict with first or subsequent notifications