1

我的应用程序在屏幕旋转时丢失了一些数据,因此我无法动态显示操作栏项目。

实际上在屏幕旋转中,它第一次调用onCreate()然后OnSuccess()OnCreateOptionsMenu()正确显示操作栏项目。但它OnCreateOptionsMmenu()之前调用的下一个轮换OnSuccess()

我已经在中定义了一个变量 OnSuccess()OnCreateOptionsMenu()所以我不能动态显示actionbarItem。

我已经定义了onRestoreInstanceState()and onSaveInstanceState(),但是它们的调用时间晚于OnCreateOptionMenu().

我在这个项目中使用了 ActionbarSherlock。如果有人可以提供线索,将不胜感激。

这是我的代码

 public class EventDisplayActivity extends BaseActivity {

    private ZEvent zEventObject;

    private String mLastUpdatedUserID;
    private String mUpdateFlag;

    private ZEvent mEventData;
    private ZVenue mVenueData;
    private ZAddress mAddressData;
    private ZUpdates mUpdateData;
    private ZRiders mRiderData;

    MenuItem decline_item;
    MenuItem edit_item ;
    MenuItem accept_item;
    MenuItem rider_item;
    MenuItem updates_item; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_display);
        setTitle("Event View");   

        vip = new ViewInfoProcessor();

        //set UpNavigation      ;
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.

        getSupportMenuInflater().inflate(R.menu.event_display, menu);

        decline_item = menu.findItem(R.id.decline_item); // for decline
        edit_item = menu.findItem(R.id.edit_item); // for edit
        accept_item = menu.findItem(R.id.accept_item); // Accept not visible
        rider_item = menu.findItem(R.id.view_artist_rider); // view artist rider
        updates_item = menu.findItem(R.id.view_all_updates); // view all updates

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int itemId =  item.getItemId();

        if(itemId == R.id.edit_item){

            Bundle b = new Bundle();
            Intent intent = new Intent(this, EventEditActivity.class);
            intent.putExtra("usage_info","event_view");
            intent.putExtra("request_from","event_view");
            intent.putExtras(b);

            intent.putExtra("EVENT_PARCEL", mEventData);
            intent.putExtra("VENUE_PARCEL", mVenueData);
            intent.putExtra("ADDRESS_PARCEL", mAddressData);
            startActivity(intent);

            return true;

        }
            return false; //return super.onOptionsItemSelected(item);
    }


    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {        


        if(mEventStatus.equals("Inquiry")){

            boolean expired = vip.isExpiredDecider(mEventDate);
            if(expired){                
                decline_item.setVisible(false); // for decline
                edit_item.setVisible(false); // for edit
                accept_item.setVisible(false); // Accept not visible
                rider_item.setVisible(false); // view artist rider
                updates_item.setVisible(false); // view all updates
            }else{
                decline_item.setVisible(true); // for decline
                edit_item.setVisible(true); // for edit

                accept_item.setVisible(false);

                if (mRiderId != null) {
                    rider_item.setVisible(true); // view artist rider
                } else {
                    rider_item.setVisible(false);  // view artist rider
                } 

                Log.i(">>>>","flag"+ mUpdateFlag);
    //here I used the mUpdateFlag varible value

               if(mUpdateFlag != null){

                   if(mUpdateFlag.equals("1") && (!mLastUpdatedUserID.equals(mLoggedUserId))){
                        updates_item.setVisible(true); // view all updates
                    }else{
                        updates_item.setVisible(false);  // Not view all updates
                    }
               }else{
                   updates_item.setVisible(false); //view all updates
               }

            }           
        }// end 



        return super.onPrepareOptionsMenu(menu);

    };

    AsyncHttpResponseHandler eventResponse = new AsyncHttpResponseHandler() {
        public void onSuccess(int arg0, String arg1) {
            System.out.println("onSuccess() in Event Dispaly" );
            try {


                JSONArray proposalArray = new JSONObject(arg1).getJSONArray("proposal");                
                JSONArray riderArray = new JSONObject(arg1).getJSONArray("rider");
                JSONArray updatesArray = new JSONObject(arg1).getJSONArray("updates");
                JSONArray agreementArray = new JSONObject(arg1).getJSONArray("agreement_details");
                JSONArray ratingsArray = new JSONObject(arg1).getJSONArray("rating_details");

                mEventData = new ZEvent(proposalArray.getJSONObject(0));    
                mVenueData = new ZVenue(proposalArray.getJSONObject(0));
                mAddressData = new ZAddress(proposalArray.getJSONObject(0));

                if(!updatesArray.isNull(0)){
                    mUpdateData =  new ZUpdates(updatesArray.getJSONObject(0));
                }

                if(!riderArray.isNull(0)){
                    mRiderData = new ZRiders(riderArray.getJSONObject(0)); 

                }               


                if(mRiderData != null){
                    mRiderId = mRiderData.getRiderID();
                    String mRiderText = mRiderData.getRiderText();
                    String mRiderStatus = mRiderData.getRiderStatus();
                }

                if(mUpdateData != null){
                    mUpdateFlag = mUpdateData.getUpdateFlag();
                    Log.i("define 1st time:::","flag"+mUpdateFlag);                   
                    mLastUpdatedUserID = mUpdateData.getLastUpdatedUserID();
                }   


                defineViews(mEventData, mVenueData, mAddressData, mRiderData, mUpdateData);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        };
        public void onFailure(Throwable arg0) {

        };      
    };




    @Override
    protected void onInit(ModelBase... data) {
        System.out.println("onInit() called in EDA");

        SharedPreferences sessionkey = getApplicationContext().getSharedPreferences("session_detail", Context.MODE_PRIVATE);        
        session_token = sessionkey.getString("session", "");
        mLoggedUserType = sessionkey.getString("user_type", ""); 
        mLoggedUserId = sessionkey.getString("user_id", "");

        Intent i = getIntent();
        Bundle extras = i.getExtras();
        zEventObject = extras.getParcelable("EVENT_ITEM"); 

        mProposalId = zEventObject.getProposalID();
        mEventStatus = zEventObject.getProposalStatus();
        mEventDate = zEventObject.getEventDate();
        mAgreedPromoterUserId = zEventObject.getAgreedPromoterUserID();
        mAgreedBAUserId = zEventObject.getAgreedAgentUserID();
        zEventObject.getLastUpdatedByUserID();

        params = new RequestParams();
        params.put("token", session_token);
        params.put("proposal_id", mProposalId);

        Log.i("PRPOPOSAL ID",""+mProposalId +""+ session_token);
        mApiClient.getView(eventViewURL, params, eventResponse);

    }

    private void defineViews(ZEvent eItem, ZVenue vItem, ZAddress aItem, ZRiders rItem, ZUpdates uItem){


        // here goes UIs
        } 

    }// End DefineView

    @Override
    protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
        outState.putParcelable("EVENT_ITEM", zEventObject);
        outState.putParcelable("UPDATE_ITEM", mUpdateData);

        System.out.println("onSaveInstanceState()");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {

        super.onRestoreInstanceState(savedInstanceState);
        zEventObject = savedInstanceState.getParcelable("EVENT_ITEM");
        mUpdateData = savedInstanceState.getParcelable("UPDATE_ITEM");

        if(mUpdateData != null){
            mUpdateFlag = mUpdateData.getUpdateFlag();
            Log.i("define 2st time:::","flag"+mUpdateFlag);                   
            mLastUpdatedUserID = mUpdateData.getLastUpdatedUserID();
        }

        System.out.println("onRestoreInstanceState()");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.activity_event_display);

    }

}

问题依然存在!。

实际上在屏幕旋转中,它第一次调用onCreate()然后OnSuccess()OnCreateOptionsMenu()正确显示操作栏项目。但它OnCreateOptionsMmenu()之前调用的下一个轮换OnSuccess()

4

2 回答 2

0

当您的屏幕旋转时,oncreate 方法再次调用该方法,我们在清单文件中使用此 android:configChanges="orientation|screenSize"。

于 2013-10-10T07:09:18.373 回答
0

您是否在清单中尝试过以下代码..

 <activity
      android:name=".YourActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="adjustPan"/>
于 2013-10-10T06:05:53.890 回答