请帮助任何人,我有使用sweetalertdialog lib的注销方法,并在导航抽屉中调用此注销
private void logout() {
SweetAlertDialog nDialog = new SweetAlertDialog(Master_Menu.this, SweetAlertDialog.CUSTOM_IMAGE_TYPE);
nDialog.setTitleText("Alert");
nDialog.setContentText("Are you sure you want to logout?");
nDialog.setConfirmText("Yes");
nDialog.setCancelText("No");
nDialog.setCustomImage(R.drawable.ic_launcher);
nDialog.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog nDialog) {
//Getting out sharedpreferences
SharedPreferences preferences = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
//Getting editor
SharedPreferences.Editor editor = preferences.edit();
String level = preferences.getString(Config.LEVEL_USER,"null");
//Puting the value false for loggedin
editor.putBoolean(Config.LOGGEDIN_SHARED_PREF, false);
//Stop the Service
if (level.equalsIgnoreCase("KRN")) {
stopService(new Intent(getApplicationContext(), getLocation.class));
Log.d("Service", "STOP");
}
//Putting blank value to email
editor.putString(Config.EMAIL_SHARED_PREF, "");
editor.putString(Config.ID_SHARED_PREF, "");
editor.putString(Config.TOKEN_SHARED_PREF, "");
editor.putString(Config.LEVEL_USER,"");
//Saving the sharedpreferences
editor.commit();
nDialog.dismiss();
//Starting login activity
Intent intent = new Intent(Master_Menu.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
nDialog.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog nDialog) {
nDialog.cancel();
}
});
nDialog.show();
}
有时意图登录活动不起作用,但确认点击监听器没问题,因为点击确认后所有共享偏好都已改变(意味着确认功能正在运行)
这是我已经尝试过的:
额外信息:
我的项目规模(清洁项目后)大约400MB
这是我的lib
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/PhotoUtil.jar')
compile files('libs/GenAsync.1.2.jar')
compile files('libs/KGJsonConverter.jar')
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.github.amigold.fundapter:library:1.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.android.support:support-v4:24.2.1'
compile 'me.spark:submitbutton:1.0.1'
compile 'com.jaredrummler:material-spinner:1.1.0'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.github.PhilJay:MPAndroidChart:v2.1.6'
compile 'com.github.paolorotolo:appintro:4.0.0'
compile 'me.wangyuwei:ParticleView:1.0.4'
compile 'com.google.android.gms:play-services:8.4.0'
}
答案 0 :(得分:0)
尝试将nDialog.dismiss();
移至setConfirmClickListener
的最后一行。您可能正在创建一个竞争条件,其中对话框可能会被解除并在它可以启动新活动之前被删除。
答案 1 :(得分:0)
您可以使用getApplicationContext()
而不是使用它,而是获取当前流程的应用程序对象的上下文。
Intent i = new Intent(getApplicationContext(), PreferencesActivity.class);
startActivity(i);