Hi, I am working on facebook api. I looked through the documentation on facebook and encoded according to the instructions in it. The code below works fine in android 2.1-3.2, but while working in android 4.0.4 it gives android.os.networkonmainthread error. I do not understand how to write the code below using AsynckTask or threads (Painless thread). Please, everything is here. Suggest me how to code so that it can run on all versions of android.Here my code.
public class Facebook4 extends Activity { public static final String mAPP_ID = "222299217893177"; public Facebook mFacebook = new Facebook(mAPP_ID); private static final String FACEBOOK_PERMISSION = "publish_stream"; private SharedPreferences mPrefs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_facebook4); ((ImageView)findViewById(R.id.facebookLogin)).setOnClickListener( loginButtonListener ); SessionStore.restore(mFacebook, this); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { mFacebook.authorizeCallback(requestCode, resultCode, data); } private OnClickListener loginButtonListener = new OnClickListener() { public void onClick( View v ) { if( !mFacebook.isSessionValid() ) { Toast.makeText(Facebook4.this, "Authorizing", Toast.LENGTH_SHORT).show(); mFacebook.authorize(Facebook4.this, new String[] {FACEBOOK_PERMISSION},Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
source share