title: Multi Threading in Android
body: <p>I am developing an Android App, which displays some images from an website in MainActivity. There are some other activities which are basically dealing with the offline contents like dealing with database and configuration. </p>
  
  <p>Currently the App is designed in such a way like, when it navigates from MainActivity to any other activities, first it will destroy itself (calling finish()) and then navigate. Likewise if navigated to MainActivity from some other Activity, those activities will be destroyed before moving.</p>
  
  <p>App works fine, initially. But if the user navigates between activities too frequently, then the image downloading task in the Main Page takes very long time.</p>
  
  <pre><code>For Example, if user navigates like
  MainActivity --&gt; Activity1 --&gt; MainActivity
  </code></pre>
  
  <p>In the above case, there is no issue displaying the images in MainActivity initially. But in the next instance, it takes unusual time.</p>
  
  <p>What I am planning to to implement a multi threading scenario, which will create a new thread every time the application trie to navigate to MainActivity and destroy the existing one.</p>
  
  <pre><code>Thread-0 : MainActivity --&gt; Activity1 (to go Main) --&gt; Kill Thread-0 and Create Thread-1
  Thread-1 : MainActivity --&gt; Activity1 --&gt; Activity2 (to go to Main) --&gt; Kill Thread-1 and create Thread-2
  </code></pre>
  
  <p>But I have no clue, how to implement the same. Any suggestion or reference link are most welcomed.</p>