로그인 되고 프로필까지 정상적으로 받아오는데요.
앱을 종료하고 다시 실행하면 session.isClosed() 가 true로 넘어옵니다…
소스코드를 보지 않고서는 왜 그렇게 되는지 알 수가 없는데요. Session로그인에 성공을 하게되면 SDK내부에서 자동으로 Session정보를 저장하게 됩니다. 때문에 위의 현상이 발생할 수 있는경우는 저장소에 저장이 제대로 되지 않았거나, 앱에서 저장소를 삭제하는 경우 일텐데요. 제보해주신 현상만으로는 소설밖에 쓸 수가 없네요… 코드나, 소스파일등 좀더 단서를 던져 주세요!
가이드를 그대로 따라한겁니다… 소스코드 어디를 보여드려야 할까요?
일단 Android Studio Gradle 환경이구요.
- build.gradle
allprojects {
repositories {
jcenter()
maven { url ‘http://devrepo.kakao.com:8088/nexus/content/groups/public/’ }
}
}
-app build.gradle
android {
…
packagingOptions {
exclude ‘META-INF/LICENSE’
exclude ‘META-INF/NOTICE’
}
}
dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile ‘com.android.support:appcompat-v7:23.0.0’
compile group: project.KAKAO_SDK_GROUP, name: ‘usermgmt’, version: project.KAKAO_SDK_VERSION
}
-
MainActivity.java
private LoginButton loginButton;
private final SessionCallback mySessionCallback = new MySessionStatusCallback();
private Session session;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);Session.initialize(this); // 로그인 버튼을 찾아온다. loginButton = (LoginButton) findViewById(R.id.com_kakao_login); // 세션 콜백 추가 session = Session.getCurrentSession(); session.addCallback(mySessionCallback); Log.i("3dfg::","kakao session isclosed " + session.isClosed()); if (session.isClosed()){ // 세션이 완전 종료된 상태로 갱신도 할 수 없으므로 명시적 오픈을 위한 로그인 버튼을 보여준다. loginButton.setVisibility(View.VISIBLE); } else { // 세션을 가지고 있거나, 갱신할 수 있는 상태로 명시적 오픈을 위한 로그인 버튼을 보여주지 않는다. loginButton.setVisibility(View.GONE); session.implicitOpen(); }
}
@Override
protected void onDestroy() {
super.onDestroy();
session.removeCallback(mySessionCallback);
}@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();//noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item);
}
private class MySessionStatusCallback implements SessionCallback {
@Override
public void onSessionOpened() {
// 프로그레스바 종료
Log.i(“3dfg::”,“onSessionOpened”);
// 세션 오픈후 보일 페이지로 이동
// final Intent intent = new Intent(SampleLoginActivity.this, SampleSignupActivity.class);
// startActivity(intent);
// finish();
}@Override public void onSessionClosed(final KakaoException exception) { // 프로그레스바 종료 Log.i("3dfg::","onSessionClosed"); // 세션 오픈을 못했으니 다시 로그인 버튼 노출. loginButton.setVisibility(View.VISIBLE); } @Override public void onSessionOpening() { //프로그레스바 시작 }
}
앱실행시 로그를 보니
W/kakao.sdk﹕ null SharedPreferences.getString
W/kakao.sdk﹕ null SharedPreferences.getString
W/kakao.sdk﹕ null SharedPreferences.getLong
W/kakao.sdk﹕ null SharedPreferences.getLong
이런 로그가 찍히는데 저장이 안됐나보네요?
처음 로그인 하고 MySessionStatusCallback 에서 onSessionOpened 은 정상호출됩니다.
그 이후에 앱 종료전 세션 저장이 잘 되었는지 확인할 수 있는 방법이 있나요?
그리고 이상한게 백키로 앱을 종료하지 않고 실행중인 상태에서 다시 빌드해서 실행이되면
세션은 살아있습니다…
Activity의 context가 아닌 application의 context를 넣어보세요^^ 요 부분은 실수가 많이 있는것 같아서 다음버전에선 수정이 될 예정입니다.