Pass a value from activity to broadcastreceiver and start a service from the broadcast receiver

后端 未结 2 906
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 15:21

I have an activity. It contains a button whose text changes dynamically. I would like to pass this text to my broadcast receiver which receives the sms. Now my broadcast rece

2条回答
  •  借酒劲吻你
    2021-01-22 15:48

    You can have your activity send an intent to the receiver, and pass the text as an extra

    Intent i= new Intent(this, YourReceiver.class);
    i.putExtra("txt", "the string value");
    startActivity(i)
    

    And then in your receiver, start the service using the startService function

提交回复
热议问题