android - How to distinguish always null object from null at first objects? -


on android app, need read information telephonymanager right after boot completed.

on first try returns null, keep calling method until returns value (usually takes 3-4 tries).

there rare devices return null don’t have value i’m looking for, app stuck on loop , crashes eventually.

how can avoid that? thought counting times tries getting value , limit number, if still getting null disable app, seems bit unstable.

my code like:

private void main () {     //...code...     while (getdeviceversion()==null)     {         log.d("error","cannot read data yet");     }      //continue code cause data received  }  private string getdeviceversion () {        telephonymanager telephony = (telephonymanager)getsystemservice(context.telephony_service);       string version = telephony.getdevicesoftwareversion();        return version;          } 

any other ideas? appreciate kind of help… thanks!

first, i'd should wait bit between 2 call getdevicesoftwareversion, telephonymanager has time read it. can use timer , timertask that.

i don't see tell if info going stay null forever of if it's going change, think can count number of attempts , stop trying after predefined number ( if want 1 sec between each call, 10 attempts should enough). of cource you'll need waiting ui user.

a warning : calling method might crash wifi-only device (see this documentation samsung). better if substitute if information android.od.build.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -