Reputation: 7
i'm currently developing an Android Application as a telemetry app for a quadrocopter. I have an udp server, which send data over the network.
There is a udp client which is in a seperate thread to handle the network connection. In my ConnectActivity i'm adding my observers like this:
Observer dataView = new DataViewActivity();
Observer osmDroidView = new OSMDroidMapsActivity();
udpClient.getDataNotifier().addObserver(dataView);
udpClient.getDataNotifier().addObserver(osmDroidView);
In my OptionsMenu i start for example my DataViewActivity:
MenuItem dataItem = menu.add("Data");
dataItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
The DataViewActivity implements the Observer interface. Now my problem is that the dataview instance which i'm adding to my observer list is another instance than my dataview i started with clicking in my options menu. Any ideas how to start the same instance via the options menu?
startActivity(new Intent(getApplicationContext(),
DataViewActivity.class));
Upvotes: 1
Views: 297
Reputation: 37126
You simply should never use new Activity()
of any kind. No matter what you use you should start your Activity only by executing startActivity call. Your curernt Activity should implement Observer interface and start new Activity when it gets notified. You can't create/store Activities - that's framework job
Upvotes: 1