Roster.getPresence will return null if the user is offline at the time of the call, or if you are not currently subscribed to that users Presence
If the user is online and you are correctly subscribed to thier presence, then it maybe because your code is running to quickly after you authenticate against the server.
For sake of testing, try and put a Thread#sleep inbetween logging in and calling the Roster code.
Its not that strange tbh. Dont forget that when you call XMPPConnection#getRoster you are requesting information across the wire which may or may not have been populated with the correct results.
If you want to ensure your Roster stays up-to-date add a RosterListener to your app. This will then listen out for Roster changes and you can update your UI accordingly
I,m still using the RosterListener, but I don’‘t need a UI. I just need to know who’'s on-line when a kind of boot wake up. It needs to know this information to send messages just to who is on line at the moment.
Your suggestion works good for now. Thankyou very much!