• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Need Facebook SDK help - posting twice!

bingobango

Well-Known Member
I have some code to create an album on Facebook when a Button is clicked. For some reason two albums are created. Both albums are the same and have the same id.

I have tried (and failed) to work out why this is happening. I have a feeling it is something to so with the fact the call is async, and something to do with callbacks. But I can't find any solid information on this.

I thought that the request in the code might be getting called when the session state changed, so that is why I check that the Session is Open, and that the Sessionstate is OPENED.

So an enlightened soul look at the code below and let me know why this is happening?

Code:
public void createNewAlbum(String albumName) {
        Session session = Session.getActiveSession();
    if (session.isOpened()) {
        SessionState state = session.getState();
        //if (state.isOpened()) {
        Bundle params = new Bundle();
        params.putString("name", albumName);

        Request.Callback callback = new Request.Callback() {

            @Override
            public void onCompleted(Response response) {

                //need to get the newly created album ID.
                try
                {
                    JSONObject graphResponse =response.getGraphObject().getInnerJSONObject();

                    try
                    {
                        albID = graphResponse.getString("id");

                        //commenting the upload  method call as two albums are being created
                        //and multiple uploads are occurring too
                        //UploadToAlbum(Session.getActiveSession(), albID);
                    }
                    catch (JSONException e)
                    {
                        Log.d( "JSON error "+ e.getMessage(), albID );
                        albID =null;
                    }

                }
                catch (Exception e) {
                    e.printStackTrace();
                    albID = null;
                }
            }
        };

        if (state.isOpened()) { // only call the request is the Session state is OPENED
        Request request = new Request(session, "me/albums",params, HttpMethod.POST,callback);
        request.executeAsync();

        }//end state session is opened

        }//end session if
    }
 
Back
Top Bottom