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

  • Home
  • SEARCH
  • 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 8927357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:12:30+00:00 2026-06-15T08:12:30+00:00

this is my MainActivity: package com.FBupdater; import java.io.IOException; import java.net.MalformedURLException; import android.app.Activity; import android.os.Bundle;

  • 0

this is my MainActivity:

package com.FBupdater;

import java.io.IOException;
import java.net.MalformedURLException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;

public class MainActivity extends Activity implements OnClickListener {

    String APP_ID = getString(R.string.APP_ID);
    Facebook fb;
    ImageButton button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fb = new Facebook(APP_ID);

        button = (ImageButton)findViewById(R.id.loginbtn);
        button.setOnClickListener(this);

        updateContentView();
    }

    private void updateContentView() {
        // TODO Auto-generated method stub
        if(fb.isSessionValid()){
            Toast.makeText(MainActivity.this, "done", Toast.LENGTH_LONG).show();
            button.setImageResource(R.drawable.logout);
        }else{
            button.setImageResource(R.drawable.login);
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        if(fb.isSessionValid()){
            //button close our session - log out of facebook
            try {
                fb.logout(getApplicationContext());
                updateContentView();
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            //login to facebook
            fb.authorize(MainActivity.this, new DialogListener() {

                @Override
                public void onFacebookError(FacebookError e) {
                    // TODO Auto-generated method stub
                    Toast.makeText(MainActivity.this, "onFBerror", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(DialogError e) {
                    // TODO Auto-generated method stub
                    Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onComplete(Bundle values) {
                    // TODO Auto-generated method stub
                    updateContentView(); 
                }

                @Override
                public void onCancel() {
                    // TODO Auto-generated method stub
                    Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_LONG).show();

                }
            });
        }
    }

}

this is my AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.FBupdater"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.FBupdater.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

this is my activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_gravity="center"
    android:background="#000000" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/notloggedinmessage"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <ImageButton
            android:id="@+id/loginbtn"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@drawable/login"
            android:src="@drawable/login" />

    </LinearLayout>

</LinearLayout>

and this the error log:

////after clicking the logout button:

11-28 15:22:56.824: D/AndroidRuntime(2123): Shutting down VM
11-28 15:22:56.824: W/dalvikvm(2123): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
11-28 15:22:57.034: E/AndroidRuntime(2123): FATAL EXCEPTION: main
11-28 15:22:57.034: E/AndroidRuntime(2123): android.os.NetworkOnMainThreadException
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.net.InetAddress.getAllByName(InetAddress.java:220)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Util.openUrl(Util.java:215)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Facebook.request(Facebook.java:777)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Facebook.request(Facebook.java:693)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.facebook.android.Facebook.logout(Facebook.java:652)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.timelystatusupdater.MainActivity.onClick(MainActivity.java:54)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.view.View.performClick(View.java:3511)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.view.View$PerformClick.run(View.java:14105)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.Handler.handleCallback(Handler.java:605)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.os.Looper.loop(Looper.java:137)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.lang.reflect.Method.invokeNative(Native Method)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at java.lang.reflect.Method.invoke(Method.java:511)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-28 15:22:57.034: E/AndroidRuntime(2123):     at dalvik.system.NativeStart.main(Native Method)
11-28 15:22:57.534: D/dalvikvm(2123): GC_CONCURRENT freed 400K, 9% free 5888K/6407K, paused 10ms+34ms
11-28 15:22:57.874: I/dalvikvm(2123): threadid=3: reacting to signal 3
11-28 15:22:57.994: I/dalvikvm(2123): Wrote stack traces to '/data/anr/traces.txt'
11-28 15:23:07.315: I/Process(2123): Sending signal. PID: 2123 SIG: 9

In the video tutorial he said it is so simple. he used facebook.logout(Context context) function. His code worked fine but mine does not.

So, what is the problem, I don’t understand. Thanks in advance.

N.B: I am new in Android and the Facebook SDK. In fact, this is my first project in android.

I run this project for min android sdk 8, target sdk 16
and when I run it in android 2.3.3 (api 10) emulator I can logout very easily but when I run it in android 4.0.3 (api 15) emulator I can login but when I try to logout the app crashes and i get the error above.

I am following a video tutorial: mybringback all 11 videos about facebook sdk in android

In the video tutorial he said it is so simple. He used facebook.logout(Context context) function. His code works fine but mine does not.

  • 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-15T08:12:32+00:00Added an answer on June 15, 2026 at 8:12 am

    aha, i have followed the AsyncFacebookRunner.java class and used its logout method and the problem is gone.

    like

    myAsyncFB.logout(Context, RequestListener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code: package com.example.sharedprefs; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View;
package com.example.temp_application; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.EditText;
This is the code from my MainActivity: package com.simple.flashlight; import android.os.Bundle; import android.app.Activity; import
This is the code: package com.elfapp; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log;
package com.elfapp; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener;
Android app gives me an error now: package com.martijngijselaar.rooster; import android.os.Bundle; import android.view.MotionEvent; import
I have an activity ( MainActivity.java ) in which content view is like this
solved by Emil thx I have following in my main package com.example.surfacetest; import android.os.Bundle;
This is a location based app.The MainActivity.java is the first file to get executed,But
I've created a custom ViewGroup based on a LinearLayout. ClearableEditText.java package test.todolist; import android.content.Context;

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.