wim_til
wim_til

Reputation: 150

Passing data from activity to child activity real time

I have a app with a main activity, a graph activity an a Bluetooth ConnectListenerImpl. The main activity search for a bluetooth device and the Bluetooth ConnectListenerImpl connect with the device and send data Message to the main activity with a Handler. And that the main activity display the data.

Now i want to display the data in the graph activity which is a child of the main activity. The start of the child activity.

bGrafiekShow = true;
Intent intent = null;
intent = new Intent(MainActivity.this, GraphActivity.class); 
startActivity(intent);

Now is my question how can i do that and what is the best way?

Little extra information. The main activity put the data from the Bluetooth in a other class this class make some calculation. After the calculation is finish the main activity put the result on the screen.

The Bluetooth device sends the data every one second.

Now I want the calculated data plot in a time graph in a child activity. But how can i send the data to the child activity.

Upvotes: 1

Views: 785

Answers (2)

L. G.
L. G.

Reputation: 9761

Put the device ID in your intent or in a bundle.

intent.putExtra("DEVICE_ID", deviceId);

When starting your second activity, retrieve device Id and connect your "child" second activity to the bluetooth via ConnectListenerImpl.

Upvotes: 0

Simon Dorociak
Simon Dorociak

Reputation: 33495

You can pass data thought Activities

  • as map of data presented like Bundle
  • with putExtra() methods of Intent
  • with Serializable or Parceable interface.

Or you can use ResultReceiver class. You can combine it with IntentService instead of Handler. In Service you will do your work and any update will be sent into ResultReceiver and receiver will update UI.

Upvotes: 2

Related Questions