我已使用Sessions在我的Android应用中集成了Facebook。我有一个登录活动,其中有一个Facebook登录按钮。我想在成功登录Facebook成功登录后转到另一个名为MainActivity的活动,应用程序关闭时没有任何错误或没有进入MainActivity。任何人都可以建议我在哪里提供代码来启动活动。这是我的代码。
ImageButton buttonLoginLogout,bb;
Session.StatusCallback statusCallback = new SessionStatusCallback();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
buttonLoginLogout = (ImageButton)findViewById(R.id.imageButton1);
buttonLoginLogout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
onClickLogin();
}
});
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
updateView();
}
@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
private void updateView() {
Session session = Session.getActiveSession();
}
});
Intent ik=new Intent(Login.this,MainActivity.class);
startActivity(ik);
} }
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
updateView();
}
}
}
答案 0 :(得分:1)
这样做。
protected void onPostExecute(Bitmap bm){
//Drawable drawable = new BitmapDrawable(getResources(), bm);
Bitmap b1=bm;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
b1.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
// Log.w("bit",""+drawable);
String encodedImage = Base64.encodeToString(b,Base64.DEFAULT);
Editor edit=pref.edit();
edit.putString("image_data",encodedImage);
edit.commit();
Intent ik=new Intent(Login.this,MainActivity.class);
startActivity(ik);
}
};
t.execute();
移动你的
Intent ik=new Intent(Login.this,MainActivity.class);
startActivity(ik);
这个代码在postexecute方法中。