title: java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity
body: <p>I have a fragment class which I want it to be like the Facebook feed. It gets data from a remote SQL DB and, at runtime, it creates the layout of a post and shows it in the fragment. </p>
  
  <p>Is there a good &amp; easy way to do so?</p>
  
  <p>I tried to do it by using a <code>BackgroundTaskJobs</code> called from the fragment. 
  This is the calling part(from inside the fragment):</p>
  
  <pre><code>BackgroundTaskJobs backgroundTaskJobs= new BackgroundTaskJobs(getActivity());
  backgroundTaskJobs.execute();
  </code></pre>
  
  <p>And this is the init at the BackgroundTaskJobs:</p>
  
  <pre><code>public BackgroundTaskJobs(Context ctx){
     this.ctx = ctx;
     activity = (Activity) ctx;
  }
  </code></pre>
  
  <p>At runtime this init crashes my up with the error:</p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.example.admin.tabbedproject, PID: 27095
  java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity
  </code></pre>
  
  <p>What can i do in order to resolve this?</p>