title: return result from asynctask to a fragment
body: <p>First of all, some info about my project:</p>
  
  <p>I have an application that consists of several fragments. (I have one class that extends FragmentActivity and another one that extends FragmentPagerAdapter.)
  So actually my code is running inside the Fragments. </p>
  
  <p>I call an asynctask inside one of the fragments to do some calculations. The asyncTask is a seperate file and the class is not located inside the Fragment class. </p>
  
  <p>So 1 file is the asynctask and another one the fragmet (variables from the fragment are not accessible direct by the asynctask!!!).</p>
  
  <p>I can display the result of the asyncTask by using ProgressDialog.
  However I want to be able to return the data (result of the asynctask) back to a variable that I have in my fragment. What I have tried so far is:</p>
  
  <ol>
  <li>Using get() from asyncatask.execute()</li>
  </ol>
  
  <p>I tried to do it like this: </p>
  
  <p>I used the following code that was called after a button click.</p>
  
  <pre><code>mytask1 = new myAsyncTask(this);
          String result =mytask1.execute(value1).get();
  </code></pre>
  
  <p>However this results in the main thread to get stuck and wait for the asynctask to complete.</p>
  
  <p>2.Using loginSharePreferens</p>
  
  <pre><code>loginPreferences = getActivity().getSharedPreferences("loginPrefs", Context.MODE_PRIVATE);
              loginPrefsEditor = loginPreferences.edit();
              loginPrefsEditor.putString("result", result);
              loginPrefsEditor.commit();
  </code></pre>
  
  <p>This gave me errors.<code>
  </code></p>
  
  <p>3.I tried also this<br>
  <code>SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext() );</code></p>
  
  <p>That was similar with the 2nd method.</p>
  
  <p>4.I tried to create a method in my fragment that would just set the value and I tried to call it inside the fragment</p>
  
  <pre><code>MyFrragment1.this.setRestult(1); // is called in the onPostExecute of the asyncTask
  
  public void setRestult(int result){
          this.test1=result; ///inside of the fragment
      }
  </code></pre>
  
  <p>This gave me error: "No enclosing instance of the type MyFragment1 is accessible in scope"</p>
  
  <p>I don't know what else to try. Any ideas ?</p>