I've just started using BroadcastReceiver (which may be my problem). I am trying to create a view from a service (yes, yes i know you cant) so i was sending the request to an invisible activity to create a visible view when i needed. it wasn't working as i wanted so i looked into BroadcastReceivers. So far everything is working with the exception that i cant compare my getStringExtra value to anything. Example) say i want to pass the variable "param" with a value of String "CREATE" to my BroadcastReceiver. It arrives to my receiver fine and with logcat i can see that indeed method is "CREATE". but if i want to check what param is with an if statement if (param=="CREATE") it never enters the if. So what am i doing wrong here?
public class Receiver extends BroadcastReceiver{
@Override
public void onReceive(Context c, Intent i) {
String stuff = i.getStringExtra("param");
log(stuff);
if (stuff=="CREATE"){
log("why dem feels");
}
if((String)i.getStringExtra("method")=="CREATE"){
log("i dont know what im doing");
}
log("FOR SOME REASON ITS SKIPPING THIS STEP");
}
//set of logs so that i dont have to keep specifying tags and shit
public void log(int in){
Log.d("TAG OF INTEGERS",Integer.toString(in));
}
public void log(String s){
Log.d("Receiver",s);
}
public void log(float f){
log((int) f);
}
}
This is the code that i am using in my service to send out the broadcast
Intent i = new Intent();
i.setClassName("com.example.starteroverlay","com.example.starteroverlay.Receiver");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String methodCall = "CREATE";
i.putExtra("param",methodCall);
//
sendBroadcast(i);
and just because i figure you guys will want to see the part of my manifest with the code
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<receiver android:name=".Receiver">
<intent-filter android:priority="0">
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</receiver>