so, what i’m trying to do is change some ui elements which are expanded in my main activity- and i want the changes to be triggered by the onReceive, which is from broadcastreceiver extended in a different separate class.
I’d like to do something like this
public class SmsReceiver extends BroadcastReceiver {
public void onReceive(context, intent){
MainActivity main = new MainActivity(); //this is my... main activity :)
main.button.setBackgroundColor(Color.green);
}//end onReceive
}//end class
in my MainActivity, i’ve set values to the GUI button element like this:
public class mainactivity extends activity... implements onclick... bla bla (){
Button button;
onCreate....{
button = (Button)findViewById(R.id.button);
so i’d like to know if when onReceive is activated, can i edit the state of a widget in ANOTHER activity by instantiating that activity and calling a setter method on it?
Your method will not work because you are creating a new instance of MainActivity. This will not reference your currently active main activity. One solution you may try is sending another intent to your activity and implementing onNewIntent(Intent newIntent) in your activity. That way you can update your main activity in that function, try passing extras in with the new information you have received.