0

The toast that says not reachable is not showing up, but all the above are showing up, why does my code stop execution on that line?

if (msg_from.equals(MainActivity.PHONENUMBER)){
                    if (msgBody.startsWith("Your")){
                        //have seen this toast
                        Toast.makeText(context, "Yes!!", Toast.LENGTH_SHORT).show();
                         //have seen this toast



                        LocationManager imLoca = SysService.locationMan;

                        Toast.makeText(context, "Yes 2!!", Toast.LENGTH_SHORT).show();
                        //have seen 



                        boolean gpsEnabled  = imLoca.isProviderEnabled(LocationManager.GPS_PROVIDER);


                        Toast.makeText(context, "not reachable", Toast.LENGTH_SHORT).show();
                        //but this does not show up,  and any thing after this line is not working;    
                        boolean netOn = imLoca.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

                        if (gpsEnabled){

                        //do some thing
                        }
                        else if (netOn){
                        //do some thing
                        }
                        else{
                            Toast.makeText(context, "Failing", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
sami
  • 49
  • 13

2 Answers2

0

I copied this code into my test project and added a toast to the if and the else if for gpsEnabled and netOn.

It looks like the first if is the one that is getting executed as gpsEnabled is true.

Hope this helps, good luck.

if (gpsEnabled){
    //do some thing
    Toast.makeText(context, "1", Toast.LENGTH_SHORT).show();
}
else if (netOn){
    //do some thing
    Toast.makeText(context, "2", Toast.LENGTH_SHORT).show();
}
else{
    Toast.makeText(context, "Failing", Toast.LENGTH_SHORT).show();
}
James
  • 3,485
  • 3
  • 20
  • 43
-1

Imloca returns null.Problem is this.

OmerFaruk
  • 292
  • 2
  • 13