vendredi 22 mai 2015

multiple instance of activity with onActivityResult

I have MainActivity calling ShowActivity and within ShowActivity user can keep open another instance of ShowAct can be opened.(In stack I'm keeping only last 2 instances for memory issues) However after all user interactions return point is ShowActivity.

Here is the possible user paths:

  • MainAct -> ShowAct-> back button or myHomeButton
  • MainAct -> ShowAct-> ...(only last 2 in stack)... -> ShowAct-> back button or myHomeButton

    ContentOpener.java //called for opening show page Intent intent = new Intent(c, ShowActivity.class); (Activity) mContext.startActivityForResult(intent,MainActivity.REQUEST_CODE_CONTENT);

mContext= ShowAct if it's opening it's own instance again...

ShowActivity.java

    @Override
    public void onDestroy() {
        mPager = null;
        mAdapter = null;

        Intent service = SendStatsService.getIntent(this, SendStatsService.NAME_CLOSE_PRESENTATION, getStatsParams());
        startService(service);
        setResult(RESULT_OK);
        super.onDestroy();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

            if(resultCode == RESULT_OK){

                super.setResult(RESULT_OK);
            }


    //this works great, send OK to MainAct      
    @Override
    public void onBackPressed() {

        try{
            int last = mSlideShowActivities.size();
            if(last>0){
                mSlideShowActivities.remove(mSlideShowActivities.size()-1);
            }
            // back to MainActivity
            setResult(RESULT_OK);

        }catch(Exception e){

        }


        super.onBackPressed();
    }

//this works great, only if it's called from last ShowActivity instance... ?

public void myHomeButtonClicked( ) {

            while(mSlideShowActivities.size()>0) {
                // back to MainActivity
                super.setResult(RESULT_OK);


                mSlideShowActivities.get(0).finish();
                mSlideShowActivities.remove(0);
            }
        }   

How can I send proper RESULT_OK to MainActivity always?

Aucun commentaire:

Enregistrer un commentaire