Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass along context from MenuItem onOptionsItemSelected to ASyncTask?
    primarykey
    data
    text
    <p>Edit: The question in one line: </p> <blockquote> <p>How to pass along context from a MenuItem onOptionsItemSelected?</p> </blockquote> <p>Edit 2: Here is a global indication of what I'm doing: <a href="https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/fragments/src/com/actionbarsherlock/sample/fragments/FragmentTabsPager.java" rel="nofollow noreferrer">https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/fragments/src/com/actionbarsherlock/sample/fragments/FragmentTabsPager.java</a></p> <hr> <p>I'm building an app based on ActionBarSherlock. It uses tabs, fragments and a viewpager. It's meant to be as versatile as possible. A tab can either contain a webview, or a listview. Here's a screenshot:</p> <p><img src="https://i.stack.imgur.com/LST1u.png" alt="http://dl.dropbox.com/u/11218283/Screenshot_2012-05-16-13-33-08.png"></p> <p>When the tab (SherlockListFragment) is first loaded, it reads content from a feed using an ASyncTask. OnPostExecute it updates the list and saves the result to a SharedPreference string (as a way of caching). As you can imagine, the AsyncTask requires context to do this. I'm calling the asynctask from the SherlockListFragment like this:</p> <pre><code>x.new refreshList(this,getActivity()).execute(); </code></pre> <p>(x being a reference to my current file).</p> <p>And transfer it to my AsyncTask like this</p> <pre><code> public refreshList(TabList a,Context b){ this.mContext = a; this.mCont = b; } </code></pre> <p>All that works fine. But as you can see I've added in a menu item for refreshing. The way I've set things up, I'm not capable of re-running the ASyncTask, since I haven't got the appropriate context information. Can anyone tell me how to perform a refresh in this situation?</p> <p>If anyone willing to help requires to see more code, I'll gladly comply.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload