1

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.

wim_til
  • 140
  • 10
  • and also u can use static variable or DataBase or file system to show msg into new screen – duggu Feb 13 '13 at 12:33
  • Do you want to show the result only on your graph or do you want to continue to listen to the data from the bluetooth and update your graph live? – L. G. Feb 13 '13 at 14:59

2 Answers2

2

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.

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
  • What you're describing is great for passing data once, at the time the activity starts. Since the poster states he wants to receive data in real-time, using your method he would need to start a new activity each time data changed. – mah Feb 13 '13 at 12:27
  • Exactly for your goal i don't have an example but i can provide you example of using **IntentService** with **ResultReceiver** so [here is example of `IntentService`](http://pastebin.com/DFRzwNLf) and [here is example of `ResultReceiver`](http://pastebin.com/9UFbmwcN) and [how start `Service`](http://pastebin.com/D5W9kKiB) – Simon Dorociak Feb 13 '13 at 13:38
0

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.

L. G.
  • 9,642
  • 7
  • 56
  • 78
  • Before posting an answer, it's generally a good idea to read the other answers and their comments ;) – mah Feb 13 '13 at 12:38
  • The difference is in the second part of the answer. – L. G. Feb 13 '13 at 12:40
  • Yes, but as was already addressed, passing data into the start intent is not providing the ability to update with real time results (but a service is). – mah Feb 13 '13 at 14:44