Question

i am doing multiple action using start activity for result in single class.One to get location,one for setting time ,and another to take image from gallery or camera,etc.These action work well in emulator ,but on device if i select start activity for result for getting the location data it returns the data perfectly ,but if i have selected the picture from gallery or have set time before taking location the data is being cleared and only the location data will be available, all previously selected data is begin erased on start activity for result .This will happen if i select any of the action not only location,the problem is the currently selected data is only available all previous data is begin removed.i will snippet the code iam using

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

    if (requestCode == PICK_FROM_CAMERA) {
        try {
            Bundle extras = data.getExtras();
            if (extras != null) {
                eventpicbitmap = extras.getParcelable("data");
                Eventpictureimageview.setImageBitmap(eventpicbitmap);
                EventImageFlag = true;

            }
        } catch (Exception e) {
            // TODO: handle exception
            EventImageFlag = false;
        }
    }

    else if (requestCode == PICK_FROM_GALLERY) {
        try {

            Bundle extras2 = data.getExtras();
            if (extras2 != null) {
                eventpicbitmap = extras2.getParcelable("data");
                Eventpictureimageview.setImageBitmap(eventpicbitmap);
                EventImageFlag = true;

            }
        } catch (Exception e) {
            // TODO: handle exception
            EventImageFlag = false;
        }
    } else if (requestCode == 606) {
        if (resultCode == RESULT_OK) {
            location = data.getExtras().getString("location_name");
            location_address = data.getExtras().getString(
                    "location_address");
            locationinfo.setText(location);
        } else {
            location = "";
            location_address = "";
        }


    }

    else if (requestCode == FACEBOOK_ACTIVITY_REQUESTCODE) {

        if (resultCode == RESULT_OK) {
            // Returns when Facebook login is success
            if (data.getStringExtra("result").equals("sucess")) {
                // Guestlayer.setVisibility(View.INVISIBLE);

            }

        }

        if (resultCode == RESULT_CANCELED) {
            // Returns when Facebook login is failed

            // Guestlayer.setVisibility(View.INVISIBLE);

        }
    }

    else if (requestCode == DATE_REQUEST) {
        if (resultCode == RESULT_OK) {
            if (data.getStringExtra("starting_time").length() > 0
                    && data.getStringExtra("ending_time").length() > 0) {
                Start_date = data.getStringExtra("starting_time");
                End_Date = data.getStringExtra("ending_time");
                durationtxt.setText(Start_date);

            } else {
                durationtxt.setText("date Not Set");

            }
        } else {
            durationtxt.setText("date Not Set");

        }
    }

    else if (requestCode == FACEBOOK_ACTIVITY_REQUESTCODE_FRIENDS) {

        if (resultCode == RESULT_OK) {
            // Returns when Facebook login is success

            if (data.getStringExtra("result").equals("sucess")) {

                /**
                 * Return Success After Login via Facebook
                 * 
                 * */

                if (!currentsession.isOpened()
                        && !currentsession.isClosed()) {
                    /**
                     * Setting Facebook permission call back
                     * 
                     * */
                    currentsession.openForRead(new Session.OpenRequest(
                            CreateEvent_Activity.this)
                            .setCallback(statusCallback));

                } else {

                    // Opens active session Facebook
                    Session.openActiveSession(CreateEvent_Activity.this,
                            true, statusCallback);
                }

            }

        }

        else if (resultCode == RESULT_CANCELED) {

            // Returns when Facebook login is failed

        }
    } else if (requestCode == Friends_Requestcode) {
        if (resultCode == RESULT_OK) {
            // Returns when Facebook login is success
            // SelectFriends.setText(data.getStringArrayListExtra(
            // "friendsname").size());

            FbFriendsUsedId = data.getStringArrayListExtra("friendsid");
            FriendsList = (ArrayList<com.pp.model.FBFriendsDetails>) data
                    .getSerializableExtra("friendsDetail");
            System.out.println(FbFriendsUsedId);

        }
    }

    else {

        /**
         * Session Callback From Facebook
         * 
         * */
        Session.getActiveSession().onActivityResult(
                CreateEvent_Activity.this, requestCode, resultCode, data);

    }

}// onActivityResult from Facebook login

in the log cat i am getting this log

12-27 12:54:56.248: D/OpenGLRenderer(18869): Flushing caches (mode 0)

Was it helpful?

Solution

I have found a solution for this issue at last,i save the values to onSaveInstanceState while calling start activity for result As shown below,

    @Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

// Saves the data  on saved Instance as a key value pair Example As below key value pair
    outState.putCharSequence("End_Date", End_Date);
    outState.putCharSequence("location", location);
    outState.putCharSequence("Start_date", Start_date);

    try {
        if (eventpicbitmap != null) {
            outState.putParcelable("bitmap", eventpicbitmap);
        }
    } catch (Exception e) {

    }



}

And the saved data is retrieved after the corresponding process on the onRestoreInstanceState as given below

    protected void onRestoreInstanceState(Bundle savedState) {

    Start_date = savedState.getCharSequence("Start_date").toString();
    End_Date = savedState.getCharSequence("End_Date").toString();
    location = savedState.getCharSequence("location").toString();


    try {
        eventpicbitmap = savedState.getParcelable("bitmap");
        Eventpictureimageview.setImageBitmap(eventpicbitmap);
        EventImageFlag = true;
    } catch (Exception e) {

    }

}

So that the data is not erased even after doing multiple startactivity for result process,And this works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top