Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9286655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:28:14+00:00 2026-06-18T19:28:14+00:00

Below code is for posting status update using facebookSDK3.0 in android. If I’m using

  • 0

Below code is for posting status update using facebookSDK3.0 in android. If I’m using UiLifeCycleHelper class its working well. But I want to post the status in facebook without using UiLifeCycleHelper class. I tried the below code, which throws error in my logcat and my application is forced closed.

public class SampleFBPostActivity extends Activity implements OnClickListener {

private EditText mPostEditText;
private Button mDoneButton;
private Session mSession;
private PendingAction pendingAction = PendingAction.NONE;

private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
private enum PendingAction {
    NONE,
    POST_STATUS_UPDATE
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fb_post);
    mPostEditText = (EditText) findViewById(R.id.post_text);
    mDoneButton = (Button) findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(this);
    mSession = Session.getActiveSession();
    if (mSession == null) {
        mSession = new Session(this);
        Session.setActiveSession(mSession);
    }
    updateUI();
    handlePendingAction();
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.done_button:
        onClickPostStatusUpdate();
        break;
    }
}

 private interface GraphObjectWithId extends GraphObject {
        String getId();
    }

 private void showPublishResult(String message, GraphObject result, FacebookRequestError error) {
        String title = null;
        String alertMessage = null;
        if (error == null) {
            title = getString(R.string.success);
            String id = result.cast(GraphObjectWithId.class).getId();
            alertMessage = getString(R.string.successfully_posted_post, message, id);
        } else {
            title = getString(R.string.error);
            alertMessage = error.getErrorMessage();
        }

        new AlertDialog.Builder(this)
                .setTitle(title)
                .setMessage(alertMessage)
                .setPositiveButton(R.string.ok, null)
                .show();
    }

    private void onClickPostStatusUpdate() {
        performPublish(PendingAction.POST_STATUS_UPDATE);
    }

    private void postStatusUpdate(final String message) {
        if (mSession != null && hasPublishPermission()) {
            Request request = Request
                    .newStatusUpdateRequest(Session.getActiveSession(), message, new Request.Callback() {
                        @Override
                        public void onCompleted(Response response) {
                            showPublishResult(message, response.getGraphObject(), response.getError());
                        }
                    });
            request.executeAsync();
        } else {
            pendingAction = PendingAction.POST_STATUS_UPDATE;
        }
    }

    private boolean hasPublishPermission() {
        Session session = Session.getActiveSession();
        return session != null && session.getPermissions().contains("publish_actions");
    }

    private void performPublish(PendingAction action) {
        Session session = Session.getActiveSession();
        if (session != null) {
            pendingAction = action;
            if (hasPublishPermission()) {
                handlePendingAction();
            } else {
                session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));
            }
        }
    }

private void updateUI() {
    Session session = Session.getActiveSession();
    boolean enableButtons = (session != null && session.isOpened());
    mDoneButton.setEnabled(enableButtons);
}

 private void handlePendingAction() {
        PendingAction previouslyPendingAction = pendingAction;
        pendingAction = PendingAction.NONE;

        switch (previouslyPendingAction) {

            case POST_STATUS_UPDATE:
                postStatusUpdate(mPostEditText.getText().toString());
                break;
        }
    }
}

Below is the error in the logcat :

  02-09 14:00:36.126: E/AndroidRuntime(2396): java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.facebook.Session.requestNewPermissions(Session.java:968)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.facebook.Session.requestNewPublishPermissions(Session.java:501)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.facebook.samples.sessionlogin.SampleFBPostActivity.performPublish(SampleFBPostActivity.java:113)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.facebook.samples.sessionlogin.SampleFBPostActivity.onClickPostStatusUpdate(SampleFBPostActivity.java:83)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.facebook.samples.sessionlogin.SampleFBPostActivity.onClick(SampleFBPostActivity.java:54)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at android.view.View.performClick(View.java:3511)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at android.view.View$PerformClick.run(View.java:14105)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at android.os.Handler.handleCallback(Handler.java:605)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at android.os.Handler.dispatchMessage(Handler.java:92)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at android.os.Looper.loop(Looper.java:137)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at android.app.ActivityThread.main(ActivityThread.java:4424)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at java.lang.reflect.Method.invokeNative(Native Method)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at java.lang.reflect.Method.invoke(Method.java:511)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  02-09 14:00:36.126: E/AndroidRuntime(2396):   at dalvik.system.NativeStart.main(Native Method)

Please help me out by not using UiLifeCycleHelper class in your solution. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:28:16+00:00Added an answer on June 18, 2026 at 7:28 pm

    Is there a particular reason you don’t want to use the UiLifecycleHelper? That class is there specifically to make your life easier, and so you don’t run into problems like this.

    If you must, the easiest way is to look at the code inside UiLifecycleHelper, and copy them to the appropriate methods in your Activity.

    For your specific Activity, I see two things wrong:

    1. You’re not opening the Session at any time (you directly call requestNewPublishPermissions, but you need to open the session first). Calling “new Session” does not open it.

    2. You’re not overriding the onActivityResult method, which is necessary to pass information back to the active session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am posting to wordpress using below code <?php require(class-IXR.php); $client = new IXR_Client('http://domain.com/xmlrpc.php');
Trying to post a status update using facebook php sdk. Code posted below. As
Can anybody help me resolve the problem for posting multipart/form-data using below code. I
Below code not work, but it's work fine for jsf1.2. Now the framework is
below code is my databasehandler class i got it from a tutorial. Beside that
In below code when I click 'Vote' a vote results screen is displayed but
My below code is posting at both times when the checkbox is checked or
So, I am posting my code below. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //
I am using below code for create TAB <div id=tabs> <ul> <li><a href=#fragment-1><span>Master</span></a></li> <li><a
First let me say sorry for the amount of code I'm posting below I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.