This one has been giving me fits for over an hour… I could swear the code is right. Am I missing something?
if((fType != "EXACT") && (dateTime > System.currentTimeMillis())){
myIntent = new Intent(getBaseContext(), MyScheduledReceiver1.class);
} else {
myIntent = new Intent(getBaseContext(),MyScheduledReceiver2.class);
}
Even if the String fType is “EXACT” & long dateTime is in the future… it’s still calling MyScheduledReceiver1.class… when since 1 is false it should be calling MyScheduledReceiver2.class.
The problem is probably that you’re comparing string references rather than comparing the values within the strings:
That will now call the
equalsmethod on the string, which will compare whether the two character sequences are equal, rather than just whetherfTypeand"EXACT"refer to the exact sameStringobject.(That will throw an exception if
fTypeis null; if you want it to just not match you could useif (!"EXACT".equals(fType) && ...)– it depends on the situations.)