multithreading - Sending Data between Activities in Android periodically. -


i have 2 activities in android application. main activity launches thread draw oscillating pendulum, can stopped "stop" button. however, if user moves second activity, should able see the calculated coordinates , parameters of oscillation (angular velocity, etc.) calculated drawing thread in real-time.

my queries :

  1. how send data thread performing oscillation second activity ? note : data generated @ regular intervals (fps), hence need send data second activity available.

  2. can use semaphores , producer-consumer solution i.e. drawing thread produces value , second activity launches thread consumes them ?

my approach : have pendulum class calculate required parameters. have extended surfaceview perform drawing thread. so, thinking of having 2 semaphores (producer , consumer), let producer thread (drawing thread) update parameters, , wait consumer(the thread launched second activity) fetch them, , repeat cycle.

another idea : let drawing thread stop executing when user moves second activity, , spawn 2 threads (consumer , producer threads) second activity perform task (namely calculate parameters , fetch them), , pendulum implements parcelable interface can passed second activity.

  1. are there better/appropriate approaches problem ?

my suggestion use 1 activity 2 fragments. don't have problem manage threads , passing of data. let both fragments communicate activity using callbacks.

another approach use service calculation of data , pass'em desired activity. can done callbacks or using binder.

both setups same idea, have model , 2 views. advantage thread drawing , calculating don't have die because of activity switch. furthermore have up-to-date data in of views , control on threads @ time.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -