title: Using Observable in Android
body: <p>I want to implement a <code>Navigation View</code> with many fragments that depend totally on a value defined in the <code>MainActivity</code>. I know that variables in MainActivity can be accessed <em>using method defined in MainActivity from other Fragments to get the value</em>, but the catch here is that the value of the variable in MainActivity may <strong>change</strong> (which runs on an <em>AsyncThread</em>). Now, I either change the code such that my <em>Fragments update their value</em> based on <em>some event in the fragment itself</em> or use <code>SharedPreference</code>. But I don't want to use SharedPreferences, neither have to check for change in the value unnecessarily many times.</p>
  
  <p>I know in RxJS, we use <strong>Observable</strong> that runs Asynchronously and works in a fashion similar to a conveyor belt. A bit of googling through the <a href="https://developer.android.com/reference/java/util/Observable.html" rel="noreferrer">official docs : Observable</a> confirmed my suspicion of something similar being available in Android, but couldn't find any proper Tutorial or explanation on how to implement it. So, am looking for a simple code snippet that might give clarity to how Observable works in Android and if it is Async and if its based similar to RxJS implementation of it. (No, I don't want RxJS implementation)</p>
  
  <p>Test Case:</p>
  
  <pre><code>MainActivity : int a, b (need observable for both variables)
  Frag1 : int a1 , b1, a1changed(),b1changed()
  Frag2 : int a2 , b2, a2Changed(), b2changed()
  </code></pre>
  
  <p>MainActivity contains integers whose value when changed should reflect in corresponding integers across the Fragments and calls separate function for each Fragment on the change being noticed.</p>