Your question is very broad, and the answer depends on some aspects of the design of your application that you did not disclose to us:
You want to get started and pass some data to it
You can start working with the intent and pass the parameter as optional (see this answer ):
Intent intent = new Intent(this, YourActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("hcedata", _data_) this.startActivity(intent);
You want to transfer data to a running instance of your activity
In this case, you can, for example, register BroadcastReceiver from your activity:
public class YourActivity extends Activity { final BroadcastReceiver hceNotificationsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if () { String hcedata = intent.getStringExtra("hcedata");
You can send an intent to this broadcast receiver to your service (note that you may need to limit broadcast transmission with the permission of the recipient to prevent data leakage for unauthorized receivers):
Intent intent = new Intent("your.hce.app.action.NOTIFY_HCE_DATA"); intent.putExtra("hcedata", _data_) this.sendBroadcast(intent);
You want to transfer data to action and get a response back to your service
As above, you can use the broadcast receiver in your service to receive a notification from your activity. Please note that you cannot bind to your HCE service, so you cannot directly refer to methods from it.
source share