static variable doesn't modify java android -


i have 2 broadcastreceivers , 1 simple class -simple class has 1 static variable -when setting static variable simpleclas.time broadcastreceiver1, varibale set correct value -but when try access simpleclass.time broadcastreceiver2, static variable remains same time, remains in init value. how thing possible? @ end static

class simpleclass{ public static long time = 0; }  class broadcastreceiver1 extends broadcastreceiver{ @override     public onreceive(){       //do stuff , update of time variable       simpleclass.time = system.currenttimemillis()/1000;      } }  class broadcastreceiver2 extends broadcastreceiver{ @override     public onreceive(){       //do stuff , read variable time modified broadcastreceiver1 , print reading       system.out.println("new value of time = " + simpleclass.time);     } } 

assuming order of events is: broadcastreceiver1 broadcastreceiver2

the value of time read time initial value 0; broadcastreceiver2 variable time @ value 0, in simpleclass class, time variable updated!!! can other operations in simpleclass new value of variable time.

somehow broadcastreceiver2 sees init value of simpleclass.time. how come? can explain?

by default, broadcastreceivers run on new process, therefore can't share same data.

you need change manifest definitions make them run on same process adding android:process="string" broadcast reciever definition


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -