Sherlock Actionbar invalidateOptionsMenu ()

I have a big mistake here. I am trying to change the action bar menu with supportInvalidateOptionsMenu (); but when the function is executed, the application closes without errors.

It's strange that everything works fine on my Galaxy Nexus (4.2.2), but it doesn’t work on my mobile mobile (Android 4.0.3), nor on my emulator with Android 2.1

Here is my code:

protected void onCreate(Bundle savedInstanceState) { ... actionbar = getSupportActionBar(); ... myWebView = (WebView) findViewById(R.id.webview); myWebView.getSettings().setJavaScriptEnabled(true); myWebView.addJavascriptInterface(new WebAppInterface(this), "Android"); myWebView.loadUrl(getString(R.string.site_load)); ... } public class WebAppInterface { SherlockActivity mActivity; WebAppInterface(SherlockActivity c) {mActivity = c;} public void setrefreshon() {showRefresh = true; mActivity.supportInvalidateOptionsMenu();} } 

Can someone help me?: /

+6
source share
1 answer

This is most likely a thread issue. You should see logged errors in accessing the user interface outside the main thread. Perhaps you filter them out? Look at the full magazine, not just the magazine for your package.

From Creating Web Applications in a Web Browser :

Note. An object attached to your JavaScript runs in a different thread, not in the thread in which it was built.

Try:

 mActivity.runOnUiThread(new Runnable(){ @Override public void run(){ mActivity.supportInvalidateOptionsMenu(); } }); 
+20
source

All Articles