So i've benn working on App which needs a BlockingQueue to communicate between the UI Thread and a handler thread. So i createt a LinkedBlockingQueue and the Thread in the onCreate of my first Activity.
BlockingQueue<String> UIqueueRx = new LinkedBlockingDeque<String>();
BlockingQueue<String> UIqueueTx = new LinkedBlockingDeque<String>();
final main m = new main(UIqueueRx,UIqueueTx);
Thread myMainThread = new Thread(m);
myMainThread.setName("AdapterThread");
myMainThread.start();
I need the BlockingQueue also during the next Actyvities, so put them into the Intent.putExtra and startet next Activity.
Intent myIntent = new Intent(v.getContext(),Start.class);
myIntent.putExtra("UIqueueRx",(Serializable) UIqueueRx);
myIntent.putExtra("UIqueueTx",(Serializable) UIqueueTx);
startActivity(myIntent);
So in my new Actyvity i wanted to take the BlockingQueue fron the Intent and bind it to my local class.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
BlockingQueue<String> UIqueueRx = (BlockingQueue<String>) getIntent().getSerializableExtra("UIqueueRx");
BlockingQueue<String> UIqueueTx = (BlockingQueue<String>) getIntent().getSerializableExtra("UIqueueTx");
//...
}
But if i later use the Queue to send Strings to the Thread nothing hapens, the String stays in Queue. So i tried to debug and mentions the id number of the Queues changed so they arent connected anymore. I also checked the Intent itself, after open the new activity there are no Extras anymore.
Anyone mention a mistake i overlooked? Is this kind of code even rational or is there a spimler way?