We cannot exactly know when the user has deleted the application. However, I came across a situation today to detect uninstallation of application which is both device and user specific (only in specific case it will be known).
The following scenario may help you where you need to delete the data based on user and device: If you are using rest API services and authentication for your App, make sure you do this to track it.
Make sure you store all your user Data by using combination of user id and device identifier as primary key.
Consider a bool value for each device identifier for each user.
When user logins to the app, make a service call and set bool to true for that device identifier and user id on server.
When user logouts of the app, make a service call and set bool to false for that device identifier and user id. Delete all the user specific data( from device and backend) while logging out(Depends on your business logic).
Now, if the user logins again and uninstalls the app without logging out, the bool will be left true and all the corresponding user and device specific data will not be deleted.
When user logins on a device, check for that bool value before updating it to true. If it is already true, it means that the same user has uninstalled this app on that particular device and installed it again on the same device.
Please note that this logic works only if there are service calls in your app and there is some authentication initially. Also, we can know this only if same user tries to login into same device. Uninstallation of application in other use cases can't be known with this logic.
Hoping that this kind of logic may help someone as we are using this logic now. I am a newbie..please guide if I am wrong.