you can use keychain . it will survive the uninstalls.
first check if userid key exists with every launch:
B4X:
p.keychainget("userid")
if it returns empty it means user is first time launching the app. So assign an id to this device
B4X:
p.keychainput("userid",Rnd(1000000,9999999))
At next launches , user id will return the random id generated above even if the user uninstall the app:
B4X:
p.keychainget("userid")
an all in one example can be :
B4X:
dim userid as string
userid = p.KeyChainGet("userid")
If userid="" Then
userid=Rnd(1000000,9999999)
p.KeyChainPut("userid",userid)
Else
End If
Log("user id : " &userid)