Android MenuItem setActionView(null) crash

On android 4.0.3 if you call MenuItem.setActionView(null) and then rotate the screen, my application will crash.

What I am trying to do is emulate the actionbar of the GMail app where if you click an item it turns into a progress bar.

However, it now saves the state of the ActionView and when it tries to restore it it says this.

Unable to start activity ComponentInfo{}: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState

Does anyone have working code for this? or a way to fix it?

Oh I use actionbarsherlock if that matter. It shouldn't because on 4.03 it just calls all the system calls.


    refreshMenuActionView = new ProgressBar(this.getActivity());

                if ( refreshMenuItem != null ) {

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(, menu);
    refreshMenuItem = menu.findItem(;
    if ( downloader != null && downloader.getStatus() == AsyncTask.Status.RUNNING ) {
    searchMenuItem = menu.findItem(;
    super.onCreateOptionsMenu(menu, inflater);


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="" >
        android:showAsAction="ifRoom" />
        android:showAsAction="always" />


Could you post a bit more of the code around the click that turns into a ProgressBar?

I use ABS and here's some code that launches an AsyncTask and ProgressBar when the user clicks a button (the code is inside a SherlockFragment):

public class LoginFragment extends SherlockFragment {

    loginButton = (Button) getActivity().findViewById(;

public OnClickListener loginListener = new OnClickListener() {
    public void onClick(View v) {
            ProgressDialog progressDialog = new ProgressDialog(getActivity());
            progressDialog.setMessage("Logging in...");
            LoginTask loginTask = new LoginTask((Polling) getActivity(), progressDialog);

Then, the ProgressDialog is controlled throughout the ASyncTask (setVisibility in each method):

public class LoginTask extends AsyncTask<String, Void, Integer> {

private ProgressDialog progressDialog;
private Polling activity;
private int id = -1;
private JSONParser jsonParser;
private static String loginURL = "";
private static String registerURL = "";
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
private static String KEY_NAME = "name";
private static String KEY_EMAIL = "email";
private static String KEY_CREATED_AT = "created_at";
private int responseCode = 0;

public LoginTask(Polling activity, ProgressDialog progressDialog)
    this.activity = activity;
    this.progressDialog = progressDialog;

protected void onPreExecute()

protected Integer doInBackground(String... arg0) {

    // check for login response
    try {
        if (json.getString(KEY_SUCCESS) != null) {
            String res = json.getString(KEY_SUCCESS);

            if(Integer.parseInt(res) == 1){
                //user successfully logged in
                // Store user details in SQLite Database
                DatabaseHandler db = new DatabaseHandler(activity.getApplicationContext());
                JSONObject json_user = json.getJSONObject("user");
                //Log.v("name", json_user.getString(KEY_NAME));
                // Clear all previous data in database
                db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), 
                        json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));                        

                responseCode = 1;
                // Close Login Screen

                responseCode = 0;
                // Error in login

    } catch (NullPointerException e) {

    catch (JSONException e) {

    return responseCode;

protected void onPostExecute(Integer responseCode)

    if (responseCode == 1) {

    if (responseCode == 0) {




Need Your Help

Send a keystroke to OS X programmatically

objective-c cocoa applescript carbon

How would you simulate the keystroke ö on Mac OS X programmatically?

How to index simple javascript hash/objects with ctags?

javascript exuberant-ctags

I use ctags to navigate my javascript apps and found that functions are added to the index and work great, yet when I have a seemingly basic hash/object it isn't added to the index/ctags file when I

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.