Hypergater Hypergater - 2 months ago 19
Java Question

if/else type statements within java

I am trying to determine upon startup whether the in-app has been purchased, this is my current code;

if (!(getSharedPreferences("purchased", 0).getBoolean("purchased", false)))
admob();
Log.d("NOT UPGRADED", "SHOW AD AS UPGRADED ALREADY");
if (!(getSharedPreferences("purchased", 0).getBoolean("purchased", true)))
admobskip();
Log.d("UPGRADED", "DO NOT SHOW AD AS UPGRADED ALREADY");


But it appears to run through all that code, rather than checking, with iOS I use if / else , however I seem unable to use that and wanted the java equivelent for this piece of code if possible? I have swapped the purchased to '
true
' on the second half of statement.

Answer

Use this instead

if (getSharedPreferences("purchased", 0).getBoolean("purchased",false) == false) {
   admob();        
   Log.d("NOT UPGRADED", "SHOW AD AS UPGRADED ALREADY");
} else if (getSharedPreferences("purchased", 0).getBoolean("purchased",true) == true) {
   admobskip();    
   Log.d("UPGRADED", "DO NOT SHOW AD AS UPGRADED ALREADY");
}
Comments